gitea-github-proxy/api/routes.go

51 lines
930 B
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
}
func SetupRoutes(params RouteParams) {
logger := params.Logger
r := params.R
r.Use(loggingMiddleware(logger))
setupApiRoutes(params)
setupSettingsRoutes(params)
setupManifestsRoutes(params)
setupAppRoutes(params)
}
type ClientParams struct {
Config *config.Config
AuthToken string
}
func getClient(params ClientParams) (*gitea.Client, error) {
options := make([]gitea.ClientOption, 0)
if len(params.AuthToken) > 0 {
options = append(options, gitea.SetToken(params.AuthToken))
}
client, err := gitea.NewClient(params.Config.GiteaUrl, options...)
if err != nil {
return nil, err
}
return client, nil
}