60 lines
1.1 KiB
Go
60 lines
1.1 KiB
Go
package api
|
|
|
|
import (
|
|
"code.gitea.io/sdk/gitea"
|
|
"git.lumeweb.com/LumeWeb/gitea-github-proxy/config"
|
|
"github.com/gorilla/mux"
|
|
"go.uber.org/fx"
|
|
"go.uber.org/zap"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
type RouteParams struct {
|
|
fx.In
|
|
Config *config.Config
|
|
Db *gorm.DB
|
|
Logger *zap.Logger
|
|
R *mux.Router
|
|
WebhookManager *WebhookManager
|
|
}
|
|
|
|
func SetupRoutes(params RouteParams) {
|
|
logger := params.Logger
|
|
r := params.R
|
|
|
|
r.Use(loggingMiddleware(logger))
|
|
|
|
setupApiRoutes(params)
|
|
setupSettingsRoutes(params)
|
|
setupManifestsRoutes(params)
|
|
setupAppRoutes(params)
|
|
setupWebhookRoutes(params)
|
|
}
|
|
|
|
type ClientParams struct {
|
|
Config *config.Config
|
|
AuthToken string
|
|
}
|
|
|
|
func getClient(params ClientParams) (*gitea.Client, error) {
|
|
options := make([]gitea.ClientOption, 0)
|
|
|
|
authToken := ""
|
|
if len(params.AuthToken) > 0 {
|
|
authToken = params.AuthToken
|
|
}
|
|
|
|
if len(authToken) == 0 {
|
|
authToken = params.Config.Oauth.Token
|
|
}
|
|
|
|
options = append(options, gitea.SetToken(authToken))
|
|
|
|
client, err := gitea.NewClient(params.Config.GiteaUrl, options...)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return client, nil
|
|
}
|