shiori/internal/http/routes/api/v1/api.go
Felipe Martin a60dbf3dc5
Run legacy API and new API at the same time. (#648)
* config: backwards comptabile dir

* remove duplicated frontend

* frontend: move assets to assets folder

* legacy routes handler in gin

* templates and asset in different embed

* new routes

* frontend routes serve old views

* added DTO for account object

* api auth calls legacy handler

* frontend: handle new error messages

* frontend: update urls

* frontend: login using new api

* updated frontend tests

* chore: remove debug route

* create shiori/gopher user if no owner is present

* server as default command

* serve -> server

* refactored database logic, allow database url

* removed unused configuration

* storage docs

* refactor cli to use cfg and deps

* check errors only in server

* log fatal instead of os exit

* dont default data directory to current dir

* fixed sqlite path

* trigger build on prs

* avoid releasing if lint/test fails

* pull request condition

* event -> event_name

* Get correct pull request number

* added workflow to delete dangling tags

* fix: nil error checking

* set gin mode first

* set gin mode before initialization

* fix logger

* allow version bump from custom ref

* Updated matrix link to workspace
2023-07-19 18:25:41 +02:00

40 lines
1.1 KiB
Go

package api_v1
import (
"github.com/gin-gonic/gin"
"github.com/go-shiori/shiori/internal/config"
"github.com/go-shiori/shiori/internal/http/middleware"
"github.com/go-shiori/shiori/internal/model"
"github.com/sirupsen/logrus"
)
type APIRoutes struct {
logger *logrus.Logger
deps *config.Dependencies
loginHandler model.LegacyLoginHandler
}
func (r *APIRoutes) Setup(g *gin.RouterGroup) model.Routes {
// Account API handles authentication in each route
r.handle(g, "/auth", NewAuthAPIRoutes(r.logger, r.deps, r.loginHandler))
// From here on, all routes require authentication
g.Use(middleware.AuthenticationRequired())
r.handle(g, "/bookmarks", NewBookmarksPIRoutes(r.logger, r.deps))
r.handle(g, "/tags", NewTagsPIRoutes(r.logger, r.deps))
return r
}
func (s *APIRoutes) handle(g *gin.RouterGroup, path string, routes model.Routes) {
group := g.Group(path)
routes.Setup(group)
}
func NewAPIRoutes(logger *logrus.Logger, deps *config.Dependencies, loginHandler model.LegacyLoginHandler) *APIRoutes {
return &APIRoutes{
logger: logger,
deps: deps,
loginHandler: loginHandler,
}
}