You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
OneAuth/api/init.go

43 lines
1.1 KiB
Go

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

//
// Copyright (C) 2024 veypi <i@veypi.com>
// 2025-03-04 16:08:06
// Distributed under terms of the MIT license.
//
package api
import (
apiAuth "github.com/veypi/vbase/api/auth"
"github.com/veypi/vbase/api/oauth"
"github.com/veypi/vbase/api/org"
"github.com/veypi/vbase/api/role"
"github.com/veypi/vbase/api/settings"
"github.com/veypi/vbase/api/user"
"github.com/veypi/vbase/api/verification"
"github.com/veypi/vbase/auth"
"github.com/veypi/vigo"
"github.com/veypi/vigo/contrib/common"
)
var Router = vigo.NewRouter()
func init() {
// 注册全局中间件
Router.Use(auth.VBaseAuth.PermLogin)
Router.After(common.JsonResponse, common.JsonErrorResponse)
// 子路由挂载
Router.Extend("/auth", apiAuth.Router)
Router.Extend("/users", user.Router)
Router.Extend("/orgs", org.Router)
Router.Extend("/roles", role.Router)
Router.Extend("/oauth", oauth.Router)
Router.Extend("/settings", settings.Router)
Router.Extend("/verification", verification.Router)
// 404 处理
Router.Any("/**", vigo.SkipBefore, "拦截未注册的api请求返回404", func(x *vigo.X) error {
return vigo.ErrNotFound
})
}