Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ all: \

backend/config/deployment/config.go: platform/local/deployment.yml backend/config/deployment/directives.yml
gonfique generate \
-pkg deployment \
-directives backend/config/deployment/directives.yml \
-config backend/config/deployment/directives.yml \
-in platform/local/deployment.yml \
-out backend/config/deployment/config.go
96 changes: 60 additions & 36 deletions backend/config/deployment/config.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 12 additions & 2 deletions backend/config/deployment/directives.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,12 @@
router:
declare: Router
meta:
package: deployment
type: Config

rules:
"*": {export: true}

"sidecar.*": {replace: time.Duration time}
"registry.*": {replace: time.Duration time}
"registry-file.*": {replace: time.Duration time}
"reception.*": {replace: time.Duration time}
"router.*": {replace: time.Duration time}
35 changes: 18 additions & 17 deletions backend/internal/web/reception/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,29 @@ package reception

import (
"fmt"
"net/http"
"net/url"

"logbook/config/deployment"
"logbook/internal/logger"
"logbook/internal/web/forwarder"
"logbook/models"
"net/http"
"net/url"

"go.ufukty.com/gohandlers/pkg/gohandlers"
)

// [Agent] is the registration Agent which helps services, and gateways to register their handlers and forwarders appropriately
type Agent struct {
deplcfg *deployment.Config
r *http.ServeMux
l *logger.Logger
c *deployment.Config
r *http.ServeMux
l *logger.Logger
}

func NewAgent(deplcfg *deployment.Config, l *logger.Logger) *Agent {
func NewAgent(c *deployment.Config, l *logger.Logger) *Agent {
return &Agent{
deplcfg: deplcfg,
r: http.NewServeMux(),
l: l.Sub("agent"),
c: c,
r: http.NewServeMux(),
l: l.Sub("agent"),
}
}

Expand All @@ -42,7 +43,7 @@ type Lister interface {
}

func (ag *Agent) RegisterEndpoints(public, private Lister) error {
origin, err := url.JoinPath(ag.deplcfg.Router.Cors.AllowOrigin)
origin, err := url.JoinPath(ag.c.Cors.AllowOrigin)
if err != nil {
return fmt.Errorf("url.JoinPath: %w", err)
}
Expand All @@ -52,7 +53,7 @@ func (ag *Agent) RegisterEndpoints(public, private Lister) error {
if public != nil {
for hn, info := range public.ListHandlers() {
c := newCors(info.Ref, origin, []string{info.Method}, corsheaders)
pl := newReceptionist(ag.deplcfg, ag.l.Sub(info.Path), c)
pl := newReceptionist(ag.c, ag.l.Sub(info.Path), c)

ag.l.Printf("registering: %s (%s, OPTIONS %s) -> %p\n", hn, info.Method, info.Path, pl)
for _, method := range []string{info.Method, "OPTIONS"} {
Expand All @@ -64,15 +65,15 @@ func (ag *Agent) RegisterEndpoints(public, private Lister) error {

if private != nil {
for hn, info := range private.ListHandlers() {
pl := newReceptionist(ag.deplcfg, ag.l.Sub(info.Path), info.Ref)
pl := newReceptionist(ag.c, ag.l.Sub(info.Path), info.Ref)
pattern := fmt.Sprintf("%s %s", info.Method, info.Path)
ag.l.Printf("registering: %s (%s) -> %p\n", hn, pattern, pl)
ag.r.Handle(pattern, pl)
}
}

ag.r.Handle("GET /ping", newReceptionist(ag.deplcfg, ag.l.Sub("ping"), http.HandlerFunc(pong)))
ag.r.Handle("GET /", newReceptionist(ag.deplcfg, ag.l.Sub("not-found"), http.HandlerFunc(http.NotFound)))
ag.r.Handle("GET /ping", newReceptionist(ag.c, ag.l.Sub("ping"), http.HandlerFunc(pong)))
ag.r.Handle("GET /", newReceptionist(ag.c, ag.l.Sub("not-found"), http.HandlerFunc(http.NotFound)))

return nil
}
Expand All @@ -81,11 +82,11 @@ func (ag *Agent) RegisterForwarders(fwds map[models.Service]*forwarder.LoadBalan
for addr, fwd := range fwds {
ag.l.Printf("registering forwarder for: %s -> %p\n", addr, fwd)
l := ag.l.Sub(fmt.Sprintf("strip-prefix(%s)", addr))
ag.r.Handle(string(addr)+"/", newReceptionist(ag.deplcfg, l, http.StripPrefix(string(addr), fwd)))
ag.r.Handle(string(addr)+"/", newReceptionist(ag.c, l, http.StripPrefix(string(addr), fwd)))
}

ag.r.Handle("/ping", newReceptionist(ag.deplcfg, ag.l.Sub("ping"), http.HandlerFunc(pong)))
ag.r.Handle("/", newReceptionist(ag.deplcfg, ag.l.Sub("not-found"), http.HandlerFunc(http.NotFound)))
ag.r.Handle("/ping", newReceptionist(ag.c, ag.l.Sub("ping"), http.HandlerFunc(pong)))
ag.r.Handle("/", newReceptionist(ag.c, ag.l.Sub("not-found"), http.HandlerFunc(http.NotFound)))

return nil
}
2 changes: 1 addition & 1 deletion dev/macos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ which go ||
which stringer ||
go install "golang.org/x/tools/cmd/stringer@latest"
which gonfique ||
go install "github.com/ufukty/gonfique@v1.3.1"
go install "go.ufukty.com/gonfique/v2@v2.0.0-alpha.9"
which sqlc ||
go install "github.com/sqlc-dev/sqlc/cmd/sqlc@latest"
which govalid ||
Expand Down
5 changes: 3 additions & 2 deletions platform/local/deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ router:
read-timeout: 1s
idle-timeout: 1s
grace-period: 1s
cors:
allow-origin: "*"

cors:
allow-origin: "*"

reception:
request-timeout: 2s
Expand Down
Loading