Browse Source

En cours de développement

master
mls-361 3 months ago
parent
commit
3bec7997a6
  1. 2
      cmd/main.go
  2. 14
      go.mod
  3. 29
      go.sum
  4. 34
      internal/api/api.go

2
cmd/main.go

@ -66,7 +66,7 @@ func createComponents(app components.Application) (components.Logger, components
return nil, nil, failure.Wrap(err, "server") ///////////////////////////////////////////////////////////////////
}
api.Build(router, model)
api.Build(logger, router, model)
return logger, server, nil
}

14
go.mod

@ -3,14 +3,14 @@ module forge.chapril.org/armen/armen
go 1.15
require (
forge.chapril.org/armen/jw v0.0.0-20210412203118-f24a805abde4
forge.chapril.org/armen/jw v0.0.0-20210418170546-b15c98296cee
forge.chapril.org/armen/memory v0.0.0-20210412203213-31c00364097c
forge.chapril.org/armen/model v0.0.0-20210417204114-a62e0ec3fce4
forge.chapril.org/mls-361/application v0.0.0-20210414132623-3cc12ee64b10
forge.chapril.org/mls-361/crypto v0.0.0-20210412210122-fd3f4aac66eb
forge.chapril.org/mls-361/failure v0.0.0-20210412202827-a8d100489f9d
forge.chapril.org/mls-361/jsonapi v0.0.0-20210416210938-8892d7c86b70
forge.chapril.org/mls-361/logger v0.0.0-20210412202904-dadda1a823de
forge.chapril.org/armen/model v0.0.0-20210418170632-dd11d78d5aee
forge.chapril.org/mls-361/application v0.0.0-20210418170244-447662583133
forge.chapril.org/mls-361/crypto v0.0.0-20210418170259-779e1f6e73c9
forge.chapril.org/mls-361/failure v0.0.0-20210418162001-830a0944aa37
forge.chapril.org/mls-361/jsonapi v0.0.0-20210418170528-5106ffb37c0d
forge.chapril.org/mls-361/logger v0.0.0-20210418170327-6857e8c31608
forge.chapril.org/mls-361/uuid v0.0.0-20210411123640-49d47af267ff
github.com/julienschmidt/httprouter v1.3.0
)

29
go.sum

@ -1,26 +1,29 @@
cloud.google.com/go v0.16.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
forge.chapril.org/armen/jw v0.0.0-20210412203118-f24a805abde4 h1:4QpXO+P7ZEekXR92qc31Wg42MC2QYdwWr0tSHytFe2A=
forge.chapril.org/armen/jw v0.0.0-20210412203118-f24a805abde4/go.mod h1:Yucy16A+11RDmTxRNi29F4eWGUjJwQ+tP8WxbP1xIMU=
forge.chapril.org/armen/jw v0.0.0-20210418170546-b15c98296cee h1:53Mwlt6M2bdjGnYvtfJBesTzNg8lB9iKHp8CZHaX/IM=
forge.chapril.org/armen/jw v0.0.0-20210418170546-b15c98296cee/go.mod h1:8rBUHomSg85wFn80HwvuzBhoyuN0hzqrSILxzmxsGHo=
forge.chapril.org/armen/memory v0.0.0-20210412203213-31c00364097c h1:djOYl2gDX9QIK1PijTPRXZDQA3SXfkS7vsSr/C0lWCM=
forge.chapril.org/armen/memory v0.0.0-20210412203213-31c00364097c/go.mod h1:/vKiV89+6GypVQ5HtbEzqEFhSpkWSIy8Y4QjM+UE3dY=
forge.chapril.org/armen/model v0.0.0-20210417204114-a62e0ec3fce4 h1:UOB4NWNgzcTZHzuou51hUvebv0nvdz7zHJ+EBpJERFo=
forge.chapril.org/armen/model v0.0.0-20210417204114-a62e0ec3fce4/go.mod h1:OxL3gFumOmVM1WmO38C6P7cfxCRHRsj0G9RdAQseQcE=
forge.chapril.org/mls-361/application v0.0.0-20210414132623-3cc12ee64b10 h1:vUnf1qBtd1/aJY0Sod5pdtVD4rAlYqWdS6E9QfhaZIM=
forge.chapril.org/mls-361/application v0.0.0-20210414132623-3cc12ee64b10/go.mod h1:POwqatcN6c54BNVrOlsJDSpRuSwoub8iRIruASBI0jM=
forge.chapril.org/armen/model v0.0.0-20210418170632-dd11d78d5aee h1:kVH3vHNBqpftZnUgwl2PwaSYA6mzAYnrlJ9oslpuEX4=
forge.chapril.org/armen/model v0.0.0-20210418170632-dd11d78d5aee/go.mod h1:77LSuNECLqoWLGAuCu9g0W3106tQhl7jNCdh841Yw3I=
forge.chapril.org/mls-361/application v0.0.0-20210418170244-447662583133 h1:gdeHIIiGbiuPRqJYAxm+d+451LLXGHScMcYbmC1dACU=
forge.chapril.org/mls-361/application v0.0.0-20210418170244-447662583133/go.mod h1:pP5yiIhq+W7vHjnESJqpaUkCAEwxzF+Qu0bSGbODHkc=
forge.chapril.org/mls-361/buffer v0.0.0-20210410182428-5dc7a7b2ae79 h1:Lh+y98uVFC7btl5FdxKNtokzHD2j14R4ZIgJECao6r4=
forge.chapril.org/mls-361/buffer v0.0.0-20210410182428-5dc7a7b2ae79/go.mod h1:JnOkXF+AEkQ4mv65rzW9eVLsauGzOYIUBQB0zUb5NGE=
forge.chapril.org/mls-361/crypto v0.0.0-20210412210122-fd3f4aac66eb h1:8pRlQkwpWHH/buFMBKBOJsuxXJebh/Gs4VFY641XDJc=
forge.chapril.org/mls-361/crypto v0.0.0-20210412210122-fd3f4aac66eb/go.mod h1:XwUr6twlpeCblJvXHeMkZxhIbX9ntiZC2KhQtyi79mo=
forge.chapril.org/mls-361/failure v0.0.0-20210412202827-a8d100489f9d h1:WXpstWIuCnizLHM/0XQJfGvElg/swaVgTp1YzPprEf4=
forge.chapril.org/mls-361/crypto v0.0.0-20210418170259-779e1f6e73c9 h1:iGwqmz0LDa1oqp1CEn/+0uvv9uisYFnXKid8SomUArg=
forge.chapril.org/mls-361/crypto v0.0.0-20210418170259-779e1f6e73c9/go.mod h1:VR2+c9Va2NNETm721gtc1AvO3HJqyTW/Tpq/CguYXIY=
forge.chapril.org/mls-361/failure v0.0.0-20210412202827-a8d100489f9d/go.mod h1:DyK2Dj+C/nhpKvGiVsWEzK8mfkk140tJPdgIvUNWv9I=
forge.chapril.org/mls-361/fqdn v0.0.0-20210412202921-28941d70bb76 h1:P5+SUAuD9pu3+B5BkQkHtUip3VxsEdwfjgc4gzMx5QY=
forge.chapril.org/mls-361/fqdn v0.0.0-20210412202921-28941d70bb76/go.mod h1:Z0AMpAr8UFXBp6Qkl66KKlw/eb2tbliAMAWPRgC/5t4=
forge.chapril.org/mls-361/jsonapi v0.0.0-20210416210938-8892d7c86b70 h1:sbuxse3p/nmD+1rcwDWENXGWhfBDR+HAvucEgXUXp2U=
forge.chapril.org/mls-361/jsonapi v0.0.0-20210416210938-8892d7c86b70/go.mod h1:ZOpC3DMkVDcxrTRgmFepr0RsvAdO9XkSR6/7vB+JX5k=
forge.chapril.org/mls-361/failure v0.0.0-20210418162001-830a0944aa37 h1:QUZ+L7q7wTuiB9yKwlOhLWd6VlPHMKJmeHyVXUROgQE=
forge.chapril.org/mls-361/failure v0.0.0-20210418162001-830a0944aa37/go.mod h1:DyK2Dj+C/nhpKvGiVsWEzK8mfkk140tJPdgIvUNWv9I=
forge.chapril.org/mls-361/fqdn v0.0.0-20210418170211-3af5dcfceb57 h1:G0qCivtJaOyjTZH0OTt1Fc6kO0CYZVMdhgXAAriROgs=
forge.chapril.org/mls-361/fqdn v0.0.0-20210418170211-3af5dcfceb57/go.mod h1:GbKe59RQ6LTPYutLN2PuZg7VGIshtb4Yo2Z+Ubn98TA=
forge.chapril.org/mls-361/jsonapi v0.0.0-20210418170528-5106ffb37c0d h1:C6yf7WM9FsDJzkN0s7FtE/XaJfgsMIHITNhT7NWqPJ4=
forge.chapril.org/mls-361/jsonapi v0.0.0-20210418170528-5106ffb37c0d/go.mod h1:gpaVfpZYjsPo59PGjBAe0I1yapjEh75tf5Xbl6CYiw8=
forge.chapril.org/mls-361/kvfmt v0.0.0-20210411202715-0e7c3e922d37 h1:6e1Y7hTJ0B8BYStiZSCdW4+v686rOpstQh2B5SWOhZU=
forge.chapril.org/mls-361/kvfmt v0.0.0-20210411202715-0e7c3e922d37/go.mod h1:bv44R0CAd8lQV4ub1hjLE3kWYwpfsW4Ro9zRnD4YOMU=
forge.chapril.org/mls-361/logger v0.0.0-20210412202904-dadda1a823de h1:6SpigDheCwoqrjwxzFLt6pSlqdKYiALt5xRkVwGFpC0=
forge.chapril.org/mls-361/logger v0.0.0-20210412202904-dadda1a823de/go.mod h1:kQ2uGfvLdRl47OxE/GI8LThroYe6RnodiqfRUbJMst0=
forge.chapril.org/mls-361/logger v0.0.0-20210418170327-6857e8c31608 h1:+rV9WP1rBix4fDWo73bNOoZFwpzwvsVzYqRGaGgvtHc=
forge.chapril.org/mls-361/logger v0.0.0-20210418170327-6857e8c31608/go.mod h1:SWqzFutF8l6j8bATORg71p3LtadaFKA0k1jPnJQmjmk=
forge.chapril.org/mls-361/uuid v0.0.0-20210411123640-49d47af267ff h1:N7L3nN/9Wlck9qtIxH6gbQ9sbWtsZ048+eDEdpvD09g=
forge.chapril.org/mls-361/uuid v0.0.0-20210411123640-49d47af267ff/go.mod h1:OAYM+f6ErfC4jbruuG2crA5W7YSpr7+wEs2MrxIzR3Q=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=

34
internal/api/api.go

@ -7,10 +7,12 @@
package api
import (
"errors"
"expvar"
"net/http"
"forge.chapril.org/armen/jw"
"forge.chapril.org/armen/model"
"forge.chapril.org/mls-361/jsonapi"
"forge.chapril.org/armen/armen/internal/components"
@ -21,27 +23,45 @@ const (
)
type api struct {
model components.Model
logger components.Logger
model components.Model
}
func newAPI(model components.Model) *api {
func newAPI(logger components.Logger, model components.Model) *api {
return &api{
model: model,
logger: logger,
model: model,
}
}
func (api *api) createJob(rw http.ResponseWriter, r *http.Request) {
job := new(jw.Job)
if err := jsonapi.Decode(rw, r, _maxBodySize, job); err != nil {
if jsonapi.Decode(rw, r, _maxBodySize, job) != nil {
return
}
_, _ = api.model.CreateJob(job) // Bad or Internal ?
done, err := api.model.CreateJob(job)
if err != nil {
if errors.Is(err, model.ErrValidation) {
jsonapi.BadRequest(rw, err)
} else {
jsonapi.InternalServerError(rw, err)
}
return
}
if done {
jsonapi.Render(rw, r, job, api.logger)
return
}
rw.WriteHeader(http.StatusOK)
}
func Build(router components.Router, model components.Model) {
api := newAPI(model)
func Build(logger components.Logger, router components.Router, model components.Model) {
api := newAPI(logger, model)
router.Get("/debug", expvar.Handler())
router.Get("/status", http.HandlerFunc(func(rw http.ResponseWriter, _ *http.Request) {

Loading…
Cancel
Save