Gestionnaire de jobs et workflows
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
dune/internal/api/api.go

70 lines
1.7 KiB

/*
------------------------------------------------------------------------------------------------------------------------
####### dune ####### Copyright (c) 2021 losyme ##################################################### MIT License #######
------------------------------------------------------------------------------------------------------------------------
*/
package api
import (
"net/http"
"forge.chapril.org/eckmuhl/context"
"forge.chapril.org/eckmuhl/middleware"
"forge.chapril.org/eckmuhl/router"
"forge.chapril.org/losyme/logger"
"forge.chapril.org/losyme/uuid"
"forge.chapril.org/dune/dune/internal/components"
)
type api struct {
cs *components.Components
logger *logger.Component
}
func new(cs *components.Components) (*api, error) {
logger, err := cs.Logger.New(uuid.New(), "api", cs.Logger.Level())
if err != nil {
return nil, err
}
logger.UseAllOutputs()
api := &api{
cs: cs,
logger: logger,
}
return api, nil
}
func (api *api) status(c *context.Context) error {
return c.JSON(http.StatusOK, nil)
}
func Setup(cs *components.Components) error {
api, err := new(cs)
if err != nil {
return err
}
cs.Router.Use(
middleware.RequestID(),
middleware.Logger(api.logger),
)
cs.Router.Group("/api", func(g *router.Group) { //api...............................................................
g.Get("/status", api.status)
g.New("/jobs", func(g2 *router.Group) { //api/jobs..............................................................
g2.Post("", api.createJob)
})
})
return nil
}
/*
######################################################################################################## @(°_°)@ #######
*/