Browse Source

En cours de développement

master
mls-361 2 months ago
parent
commit
b5c43fe73d
  1. 2
      cmd/main.go
  2. 1
      go.mod
  3. 2
      go.sum
  4. 16
      internal/api/api.go
  5. 5
      internal/components/components.go
  6. 36
      internal/gui/gui.go
  7. 25
      internal/gui/home.go
  8. 32
      internal/gui/layout.go
  9. 27
      internal/router/router.go

2
cmd/main.go

@ -23,6 +23,7 @@ import (
"forge.chapril.org/armen/armen/internal/config"
"forge.chapril.org/armen/armen/internal/crypto"
"forge.chapril.org/armen/armen/internal/demo"
"forge.chapril.org/armen/armen/internal/gui"
"forge.chapril.org/armen/armen/internal/logger"
"forge.chapril.org/armen/armen/internal/model"
"forge.chapril.org/armen/armen/internal/router"
@ -89,6 +90,7 @@ func buildComponents(ccs *components.Components) error {
}
api.Build(ccs)
gui.Build(ccs)
return nil
}

1
go.mod

@ -15,4 +15,5 @@ require (
forge.chapril.org/mls-361/logger v0.0.0-20210511132528-884fa4c98c68
forge.chapril.org/mls-361/uuid v0.0.0-20210511091055-533cd6b13c6f
github.com/julienschmidt/httprouter v1.3.0
github.com/maragudk/gomponents v0.16.0
)

2
go.sum

@ -30,3 +30,5 @@ forge.chapril.org/mls-361/uuid v0.0.0-20210511091055-533cd6b13c6f h1:ycJeyJjfkgE
forge.chapril.org/mls-361/uuid v0.0.0-20210511091055-533cd6b13c6f/go.mod h1:OAYM+f6ErfC4jbruuG2crA5W7YSpr7+wEs2MrxIzR3Q=
github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U=
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
github.com/maragudk/gomponents v0.16.0 h1:qoFF52ePoX27b6uvLGfGNcIfN/F6NSg9YCtqoipBXuM=
github.com/maragudk/gomponents v0.16.0/go.mod h1:0OdlqOoqxcwvhBFrp8wlKHnEXhNB7IVhb8GuARmd+tI=

16
internal/api/api.go

@ -19,9 +19,7 @@ import (
"forge.chapril.org/armen/armen/internal/middleware"
)
const (
_maxBodySize = 1024 * 32
)
const _maxBodySize = 1024 * 32
type api struct {
logger components.Logger
@ -135,14 +133,10 @@ func Build(ccs *components.Components) {
api := newAPI(ccs)
router := ccs.Router
router.Get("/api/status", api.debug(func(r *jsonapi.Request) {
r.RenderOK()
}))
router.Post("/api/job/create", api.debug(api.createJob))
router.Get("/api/job/next/:namespace", api.trace(api.nextJob))
router.Post("/api/job/update", api.debug(api.updateJob))
router.Post("/api/workflow/create", api.debug(api.createWorkflow))
router.PostJSON("/api/job/create", api.debug(api.createJob))
router.GetJSON("/api/job/next/:namespace", api.trace(api.nextJob))
router.PostJSON("/api/job/update", api.debug(api.updateJob))
router.PostJSON("/api/workflow/create", api.debug(api.createWorkflow))
}
/*

5
internal/components/components.go

@ -51,8 +51,9 @@ type Model interface {
// Router AFAIRE.
type Router interface {
Handler() http.Handler
Get(path string, handler jsonapi.Handler)
Post(path string, handler jsonapi.Handler)
Get(path string, handler http.Handler)
GetJSON(path string, handler jsonapi.Handler)
PostJSON(path string, handler jsonapi.Handler)
}
// Server AFAIRE.

36
internal/gui/gui.go

@ -0,0 +1,36 @@
/*
------------------------------------------------------------------------------------------------------------------------
####### gui ####### Copyright (c) 2021 mls-361 #########g############################################ MIT License #######
------------------------------------------------------------------------------------------------------------------------
*/
package gui
import (
"net/http"
"forge.chapril.org/armen/armen/internal/components"
)
type gui struct {
storage components.Storage
}
func newGUI(ccs *components.Components) *gui {
return &gui{
storage: ccs.Storage,
}
}
func Build(ccs *components.Components) {
gui := newGUI(ccs)
router := ccs.Router
router.Get("/", http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
_ = gui.Home().Render(w)
}))
}
/*
######################################################################################################## @(°_°)@ #######
*/

25
internal/gui/home.go

@ -0,0 +1,25 @@
/*
------------------------------------------------------------------------------------------------------------------------
####### gui ####### Copyright (c) 2021 mls-361 ##################################################### MIT License #######
------------------------------------------------------------------------------------------------------------------------
*/
package gui
import (
g "github.com/maragudk/gomponents"
. "github.com/maragudk/gomponents/html"
)
func (gui *gui) Home() g.Node {
return gui.page(
"home",
P(
g.Text("Hello"),
),
)
}
/*
######################################################################################################## @(°_°)@ #######
*/

32
internal/gui/layout.go

@ -0,0 +1,32 @@
/*
------------------------------------------------------------------------------------------------------------------------
####### gui ####### Copyright (c) 2021 mls-361 ##################################################### MIT License #######
------------------------------------------------------------------------------------------------------------------------
*/
package gui
import (
g "github.com/maragudk/gomponents"
c "github.com/maragudk/gomponents/components"
. "github.com/maragudk/gomponents/html"
)
func (gui *gui) page(title string, content g.Node) g.Node {
return c.HTML5(
c.HTML5Props{
Title: title,
Language: "en",
Head: []g.Node{
Link(Rel("stylesheet"), Href("https://unpkg.com/tailwindcss@^2/dist/tailwind.min.css"), Type("text/css")),
},
Body: []g.Node{
content,
},
},
)
}
/*
######################################################################################################## @(°_°)@ #######
*/

27
internal/router/router.go

@ -43,6 +43,14 @@ func Build(_ *components.Components) components.Router {
},
)
cr.mux.Handle(
http.MethodGet,
"/status",
func(w http.ResponseWriter, _ *http.Request, _ httprouter.Params) {
w.WriteHeader(http.StatusOK)
},
)
return cr
}
@ -51,7 +59,12 @@ func (cr *router) Handler() http.Handler {
return cr.mux
}
func (cr *router) handle(method string, path string, handler jsonapi.Handler) {
// Get AFAIRE.
func (cr *router) Get(path string, handler http.Handler) {
cr.mux.Handler(http.MethodGet, path, handler)
}
func (cr *router) handleJSON(method string, path string, handler jsonapi.Handler) {
cr.mux.Handle(
method,
path,
@ -71,14 +84,14 @@ func (cr *router) handle(method string, path string, handler jsonapi.Handler) {
)
}
// Get AFAIRE.
func (cr *router) Get(path string, handler jsonapi.Handler) {
cr.handle(http.MethodGet, path, handler)
// GetJSON AFAIRE.
func (cr *router) GetJSON(path string, handler jsonapi.Handler) {
cr.handleJSON(http.MethodGet, path, handler)
}
// Post AFAIRE.
func (cr *router) Post(path string, handler jsonapi.Handler) {
cr.handle(http.MethodPost, path, handler)
// PostJSON AFAIRE.
func (cr *router) PostJSON(path string, handler jsonapi.Handler) {
cr.handleJSON(http.MethodPost, path, handler)
}
/*

Loading…
Cancel
Save