49 lines
905 B
Go
49 lines
905 B
Go
package api
|
|
|
|
import (
|
|
"code.gitea.io/sdk/gitea"
|
|
"git.lumeweb.com/LumeWeb/gitea-github-proxy/config"
|
|
"github.com/gorilla/mux"
|
|
"go.uber.org/zap"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
type RouteParams struct {
|
|
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
|
|
}
|