gitea-github-proxy/api/routes.go

63 lines
1.2 KiB
Go
Raw Normal View History

package api
import (
"code.gitea.io/sdk/gitea"
"git.lumeweb.com/LumeWeb/gitea-github-proxy/config"
"github.com/gorilla/mux"
2024-02-11 05:50:51 +00:00
"go.uber.org/fx"
"go.uber.org/zap"
"gorm.io/gorm"
)
type RouteParams struct {
2024-02-11 05:50:51 +00:00
fx.In
Config *config.Config
Db *gorm.DB
Logger *zap.Logger
R *mux.Router
WebhookManager *WebhookManager
2024-02-11 21:30:03 +00:00
Oauth *Oauth
}
func SetupRoutes(params RouteParams) {
logger := params.Logger
r := params.R
r.Use(loggingMiddleware(logger))
setupApiRoutes(params)
setupSettingsRoutes(params)
setupManifestsRoutes(params)
setupAppRoutes(params)
setupAppInstallRoutes(params)
setupWebhookRoutes(params)
setupRestRoutes(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
}