Compare commits
16 Commits
7a88321a69
...
extension
Author | SHA1 | Date | |
---|---|---|---|
8b85f60e63 | |||
fe90d81b5d | |||
9343970672 | |||
b73723b5f5 | |||
985ce3eba3 | |||
f48503f2b6 | |||
5d53e32316 | |||
76dea96a46 | |||
636b2dbf8f | |||
42aba649c8 | |||
67e87adf89 | |||
60d9fde890 | |||
bc82c8b59c | |||
682d70ed30 | |||
fa49bcf0c7 | |||
e4293b7b8b |
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,3 +1,3 @@
|
|||||||
/coverage
|
/coverage
|
||||||
/bin
|
/bin
|
||||||
rice-box.go
|
/.vscode
|
7
Makefile
7
Makefile
@ -1,10 +1,3 @@
|
|||||||
build: embed
|
|
||||||
CGO_ENABLED=0 go build -o ./bin/scaffold ./cmd/scaffold
|
|
||||||
|
|
||||||
embed:
|
|
||||||
find ./ -name rice-box.go | xargs rm -f
|
|
||||||
rice embed-go -i ./cmd/scaffold/command
|
|
||||||
|
|
||||||
test:
|
test:
|
||||||
go clean -testcache
|
go clean -testcache
|
||||||
go test -v -race ./...
|
go test -v -race ./...
|
||||||
|
@ -1,4 +0,0 @@
|
|||||||
/release
|
|
||||||
/data
|
|
||||||
/vendor
|
|
||||||
/bin
|
|
@ -1,28 +0,0 @@
|
|||||||
build: vendor
|
|
||||||
CGO_ENABLED=0 go build -mod=vendor -v -o bin/server ./cmd/server
|
|
||||||
|
|
||||||
test:
|
|
||||||
go test -v -race ./...
|
|
||||||
|
|
||||||
release:
|
|
||||||
@$(SHELL) ./misc/script/release.sh
|
|
||||||
|
|
||||||
vendor:
|
|
||||||
go mod vendor
|
|
||||||
|
|
||||||
tidy:
|
|
||||||
go mod tidy
|
|
||||||
|
|
||||||
watch:
|
|
||||||
modd
|
|
||||||
|
|
||||||
lint:
|
|
||||||
golangci-lint run --enable-all
|
|
||||||
|
|
||||||
clean:
|
|
||||||
rm -rf release
|
|
||||||
rm -rf data
|
|
||||||
rm -rf vendor
|
|
||||||
rm -rf bin
|
|
||||||
|
|
||||||
.PHONY: lint watch build vendor tidy release
|
|
@ -1,15 +0,0 @@
|
|||||||
# {{ .ProjectName }}
|
|
||||||
|
|
||||||
## Démarrer avec les sources
|
|
||||||
|
|
||||||
```
|
|
||||||
make build
|
|
||||||
```
|
|
||||||
|
|
||||||
## FAQ
|
|
||||||
|
|
||||||
### Générer une version de distribution
|
|
||||||
|
|
||||||
```
|
|
||||||
make release
|
|
||||||
```
|
|
@ -1,78 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"log"
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"gitlab.com/wpetit/goweb/template/html"
|
|
||||||
|
|
||||||
"{{ .ProjectNamespace }}/internal/config"
|
|
||||||
"github.com/gorilla/sessions"
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
"gitlab.com/wpetit/goweb/service"
|
|
||||||
"gitlab.com/wpetit/goweb/service/build"
|
|
||||||
"gitlab.com/wpetit/goweb/service/session"
|
|
||||||
"gitlab.com/wpetit/goweb/service/template"
|
|
||||||
"gitlab.com/wpetit/goweb/session/gorilla"
|
|
||||||
)
|
|
||||||
|
|
||||||
func getServiceContainer(conf *config.Config) (*service.Container, error) {
|
|
||||||
// Initialize and configure service container
|
|
||||||
ctn := service.NewContainer()
|
|
||||||
|
|
||||||
ctn.Provide(build.ServiceName, build.ServiceProvider(ProjectVersion, GitRef, BuildDate))
|
|
||||||
|
|
||||||
// Generate random cookie authentication key if none is set
|
|
||||||
if conf.HTTP.CookieAuthenticationKey == "" {
|
|
||||||
log.Println("could not find cookie authentication key. generating one...")
|
|
||||||
|
|
||||||
cookieAuthenticationKey, err := gorilla.GenerateRandomBytes(64)
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Wrap(err, "could not generate cookie authentication key")
|
|
||||||
}
|
|
||||||
|
|
||||||
conf.HTTP.CookieAuthenticationKey = string(cookieAuthenticationKey)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Generate random cookie encryption key if none is set
|
|
||||||
if conf.HTTP.CookieEncryptionKey == "" {
|
|
||||||
log.Println("could not find cookie encryption key. generating one...")
|
|
||||||
|
|
||||||
cookieEncryptionKey, err := gorilla.GenerateRandomBytes(32)
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Wrap(err, "could not generate cookie encryption key")
|
|
||||||
}
|
|
||||||
|
|
||||||
conf.HTTP.CookieEncryptionKey = string(cookieEncryptionKey)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create and initialize HTTP session service provider
|
|
||||||
cookieStore := sessions.NewCookieStore(
|
|
||||||
[]byte(conf.HTTP.CookieAuthenticationKey),
|
|
||||||
[]byte(conf.HTTP.CookieEncryptionKey),
|
|
||||||
)
|
|
||||||
|
|
||||||
// Define default cookie options
|
|
||||||
cookieStore.Options = &sessions.Options{
|
|
||||||
Path: "/",
|
|
||||||
HttpOnly: true,
|
|
||||||
MaxAge: conf.HTTP.CookieMaxAge,
|
|
||||||
SameSite: http.SameSiteStrictMode,
|
|
||||||
}
|
|
||||||
|
|
||||||
ctn.Provide(
|
|
||||||
session.ServiceName,
|
|
||||||
gorilla.ServiceProvider("scaffold-test", cookieStore),
|
|
||||||
)
|
|
||||||
|
|
||||||
// Create and expose template service provider
|
|
||||||
// Create and expose template service provider
|
|
||||||
ctn.Provide(template.ServiceName, html.ServiceProvider(
|
|
||||||
conf.HTTP.TemplateDir,
|
|
||||||
))
|
|
||||||
|
|
||||||
// Create and expose config service provider
|
|
||||||
ctn.Provide(config.ServiceName, config.ServiceProvider(conf))
|
|
||||||
|
|
||||||
return ctn, nil
|
|
||||||
}
|
|
@ -1,111 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"{{ .ProjectNamespace }}/internal/route"
|
|
||||||
"github.com/go-chi/chi"
|
|
||||||
"github.com/go-chi/chi/middleware"
|
|
||||||
"gitlab.com/wpetit/goweb/middleware/container"
|
|
||||||
|
|
||||||
"flag"
|
|
||||||
"fmt"
|
|
||||||
"log"
|
|
||||||
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"{{ .ProjectNamespace }}/internal/config"
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
)
|
|
||||||
|
|
||||||
//nolint: gochecknoglobals
|
|
||||||
var (
|
|
||||||
configFile = ""
|
|
||||||
workdir = ""
|
|
||||||
dumpConfig = false
|
|
||||||
version = false
|
|
||||||
)
|
|
||||||
|
|
||||||
// nolint: gochecknoglobals
|
|
||||||
var (
|
|
||||||
GitRef = "unknown"
|
|
||||||
ProjectVersion = "unknown"
|
|
||||||
BuildDate = "unknown"
|
|
||||||
)
|
|
||||||
|
|
||||||
//nolint: gochecknoinits
|
|
||||||
func init() {
|
|
||||||
flag.StringVar(&configFile, "config", configFile, "configuration file")
|
|
||||||
flag.StringVar(&workdir, "workdir", workdir, "working directory")
|
|
||||||
flag.BoolVar(&dumpConfig, "dump-config", dumpConfig, "dump configuration and exit")
|
|
||||||
flag.BoolVar(&version, "version", version, "show version and exit")
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
flag.Parse()
|
|
||||||
|
|
||||||
if version {
|
|
||||||
fmt.Printf("%s (%s) - %s\n", ProjectVersion, GitRef, BuildDate)
|
|
||||||
|
|
||||||
os.Exit(0)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Switch to new working directory if defined
|
|
||||||
if workdir != "" {
|
|
||||||
if err := os.Chdir(workdir); err != nil {
|
|
||||||
log.Fatalf("%+v", errors.Wrapf(err, "could not change working directory to '%s'", workdir))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Load configuration file if defined, use default configuration otherwise
|
|
||||||
var conf *config.Config
|
|
||||||
|
|
||||||
var err error
|
|
||||||
|
|
||||||
if configFile != "" {
|
|
||||||
conf, err = config.NewFromFile(configFile)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("%+v", errors.Wrapf(err, "could not load config file '%s'", configFile))
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if dumpConfig {
|
|
||||||
conf = config.NewDumpDefault()
|
|
||||||
} else {
|
|
||||||
conf = config.NewDefault()
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// Dump configuration if asked
|
|
||||||
if dumpConfig {
|
|
||||||
if err := config.Dump(conf, os.Stdout); err != nil {
|
|
||||||
log.Fatalf("%+v", errors.Wrap(err, "could not dump config"))
|
|
||||||
}
|
|
||||||
|
|
||||||
os.Exit(0)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create service container
|
|
||||||
ctn, err := getServiceContainer(conf)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("%+v", errors.Wrap(err, "could not create service container"))
|
|
||||||
}
|
|
||||||
|
|
||||||
r := chi.NewRouter()
|
|
||||||
|
|
||||||
// Define base middlewares
|
|
||||||
r.Use(middleware.Logger)
|
|
||||||
r.Use(middleware.Recoverer)
|
|
||||||
|
|
||||||
// Expose service container on router
|
|
||||||
r.Use(container.ServiceContainer(ctn))
|
|
||||||
|
|
||||||
// Define routes
|
|
||||||
if err := route.Mount(r, conf); err != nil {
|
|
||||||
log.Fatalf("%+v", errors.Wrap(err, "could not mount http routes"))
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := http.ListenAndServe(conf.HTTP.Address, r); err != nil {
|
|
||||||
log.Fatalf("%+v", errors.Wrapf(err, "could not listen on '%s'", conf.HTTP.Address))
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,18 +0,0 @@
|
|||||||
{{define "base"}}
|
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8">
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
||||||
<title>{{block "title" . -}}{{- end}}</title>
|
|
||||||
{{- block "head_style" . -}}
|
|
||||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@0.8.0/css/bulma.min.css" />
|
|
||||||
{{end}}
|
|
||||||
{{- block "head_script" . -}}{{end}}
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
{{- block "body" . -}}{{- end -}}
|
|
||||||
{{- block "body_script" . -}}{{end}}
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
{{end}}
|
|
@ -1,23 +0,0 @@
|
|||||||
{{define "flash"}}
|
|
||||||
<div class="flash has-margin-top-small has-margin-bottom-small">
|
|
||||||
{{- range .Flashes -}}
|
|
||||||
{{- if eq .Type "error" -}}
|
|
||||||
{{template "flash_message" map "Title" "Erreur" "MessageClass" "is-danger" "Message" .Message }}
|
|
||||||
{{- else if eq .Type "warn" -}}
|
|
||||||
{{template "flash_message" map "Title" "Attention" "MessageClass" "is-warning" "Message" .Message }}
|
|
||||||
{{- else if eq .Type "success" -}}
|
|
||||||
{{template "flash_message" map "Title" "Succès" "MessageClass" "is-success" "Message" .Message }}
|
|
||||||
{{- else -}}
|
|
||||||
{{template "flash_message" map "Title" "Information" "MessageClass" "is-info" "Message" .Message }}
|
|
||||||
{{- end -}}
|
|
||||||
{{- end -}}
|
|
||||||
</div>
|
|
||||||
{{end}}
|
|
||||||
|
|
||||||
{{define "flash_message" -}}
|
|
||||||
<div class="message {{.MessageClass}}">
|
|
||||||
<div class="message-body">
|
|
||||||
<span class="has-text-weight-bold">{{.Title}}</span> {{.Message}}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{{- end}}
|
|
@ -1,7 +0,0 @@
|
|||||||
{{define "footer"}}
|
|
||||||
<p class="has-margin-top-small has-text-right is-size-7 has-text-grey">
|
|
||||||
Version: {{ .BuildInfo.ProjectVersion }} -
|
|
||||||
Réf.: {{ .BuildInfo.GitRef }} -
|
|
||||||
Date de construction: {{ .BuildInfo.BuildDate }}
|
|
||||||
</p>
|
|
||||||
{{end}}
|
|
@ -1,11 +0,0 @@
|
|||||||
{{define "header"}}
|
|
||||||
<div class="columns is-mobile">
|
|
||||||
<div class="column is-4-tablet is-8-mobile">
|
|
||||||
<div class="columns is-mobile is-gapless">
|
|
||||||
<div class="column is-narrow">
|
|
||||||
<h1 class="is-size-3 title"><a href="/" rel="Homepage" class="has-text-black">Your project</a></h1>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{{end}}
|
|
@ -1,11 +0,0 @@
|
|||||||
{{define "title"}}Accueil{{end}}
|
|
||||||
{{define "body"}}
|
|
||||||
<section class="home is-fullheight section">
|
|
||||||
<div class="container">
|
|
||||||
{{template "header" .}}
|
|
||||||
<h1>Bienvenue !</h1>
|
|
||||||
{{template "footer" .}}
|
|
||||||
</div>
|
|
||||||
</section>
|
|
||||||
{{end}}
|
|
||||||
{{template "base" .}}
|
|
@ -1 +0,0 @@
|
|||||||
module {{ .ProjectNamespace }}
|
|
@ -1,71 +0,0 @@
|
|||||||
package config
|
|
||||||
|
|
||||||
import (
|
|
||||||
"io"
|
|
||||||
"io/ioutil"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
|
|
||||||
"gopkg.in/yaml.v2"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Config struct {
|
|
||||||
HTTP HTTPConfig `yaml:"http"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewFromFile retrieves the configuration from the given file
|
|
||||||
func NewFromFile(filepath string) (*Config, error) {
|
|
||||||
config := NewDefault()
|
|
||||||
|
|
||||||
data, err := ioutil.ReadFile(filepath)
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Wrapf(err, "could not read file '%s'", filepath)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := yaml.Unmarshal(data, config); err != nil {
|
|
||||||
return nil, errors.Wrapf(err, "could not unmarshal configuration")
|
|
||||||
}
|
|
||||||
|
|
||||||
return config, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
type HTTPConfig struct {
|
|
||||||
Address string `yaml:"address"`
|
|
||||||
CookieAuthenticationKey string `yaml:"cookieAuthenticationKey"`
|
|
||||||
CookieEncryptionKey string `yaml:"cookieEncryptionKey"`
|
|
||||||
CookieMaxAge int `yaml:"cookieMaxAge"`
|
|
||||||
TemplateDir string `yaml:"templateDir"`
|
|
||||||
PublicDir string `yaml:"publicDir"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewDumpDefault() *Config {
|
|
||||||
config := NewDefault()
|
|
||||||
return config
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewDefault() *Config {
|
|
||||||
return &Config{
|
|
||||||
HTTP: HTTPConfig{
|
|
||||||
Address: ":3000",
|
|
||||||
CookieAuthenticationKey: "",
|
|
||||||
CookieEncryptionKey: "",
|
|
||||||
CookieMaxAge: int((time.Hour * 1).Seconds()), // 1 hour
|
|
||||||
TemplateDir: "template",
|
|
||||||
PublicDir: "public",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func Dump(config *Config, w io.Writer) error {
|
|
||||||
data, err := yaml.Marshal(config)
|
|
||||||
if err != nil {
|
|
||||||
return errors.Wrap(err, "could not dump config")
|
|
||||||
}
|
|
||||||
|
|
||||||
if _, err := w.Write(data); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
@ -1,9 +0,0 @@
|
|||||||
package config
|
|
||||||
|
|
||||||
import "gitlab.com/wpetit/goweb/service"
|
|
||||||
|
|
||||||
func ServiceProvider(config *Config) service.Provider {
|
|
||||||
return func(ctn *service.Container) (interface{}, error) {
|
|
||||||
return config, nil
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,33 +0,0 @@
|
|||||||
package config
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
"gitlab.com/wpetit/goweb/service"
|
|
||||||
)
|
|
||||||
|
|
||||||
const ServiceName service.Name = "config"
|
|
||||||
|
|
||||||
// From retrieves the config service in the given container
|
|
||||||
func From(container *service.Container) (*Config, error) {
|
|
||||||
service, err := container.Service(ServiceName)
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Wrapf(err, "error while retrieving '%s' service", ServiceName)
|
|
||||||
}
|
|
||||||
|
|
||||||
srv, ok := service.(*Config)
|
|
||||||
if !ok {
|
|
||||||
return nil, errors.Errorf("retrieved service is not a valid '%s' service", ServiceName)
|
|
||||||
}
|
|
||||||
|
|
||||||
return srv, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Must retrieves the config service in the given container or panic otherwise
|
|
||||||
func Must(container *service.Container) *Config {
|
|
||||||
srv, err := From(container)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return srv
|
|
||||||
}
|
|
@ -1,24 +0,0 @@
|
|||||||
package route
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
"gitlab.com/wpetit/goweb/middleware/container"
|
|
||||||
"gitlab.com/wpetit/goweb/service/template"
|
|
||||||
"gitlab.com/wpetit/goweb/template/html"
|
|
||||||
)
|
|
||||||
|
|
||||||
func extendTemplateData(w http.ResponseWriter, r *http.Request, data template.Data) template.Data {
|
|
||||||
ctn := container.Must(r.Context())
|
|
||||||
data, err := template.Extend(data,
|
|
||||||
html.WithFlashes(w, r, ctn),
|
|
||||||
template.WithBuildInfo(w, r, ctn),
|
|
||||||
)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
panic(errors.Wrap(err, "could not extend template data"))
|
|
||||||
}
|
|
||||||
|
|
||||||
return data
|
|
||||||
}
|
|
@ -1,20 +0,0 @@
|
|||||||
package route
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
"gitlab.com/wpetit/goweb/middleware/container"
|
|
||||||
"gitlab.com/wpetit/goweb/service/template"
|
|
||||||
)
|
|
||||||
|
|
||||||
func serveHomePage(w http.ResponseWriter, r *http.Request) {
|
|
||||||
ctn := container.Must(r.Context())
|
|
||||||
tmpl := template.Must(ctn)
|
|
||||||
|
|
||||||
data := extendTemplateData(w, r, template.Data{})
|
|
||||||
|
|
||||||
if err := tmpl.RenderPage(w, "home.html.tmpl", data); err != nil {
|
|
||||||
panic(errors.Wrapf(err, "could not render '%s' page", r.URL.Path))
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,34 +0,0 @@
|
|||||||
package route
|
|
||||||
|
|
||||||
import (
|
|
||||||
"{{ .ProjectNamespace }}/internal/config"
|
|
||||||
|
|
||||||
"github.com/go-chi/chi"
|
|
||||||
"github.com/gorilla/csrf"
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
"gitlab.com/wpetit/goweb/static"
|
|
||||||
"gitlab.com/wpetit/goweb/session/gorilla"
|
|
||||||
)
|
|
||||||
|
|
||||||
func Mount(r *chi.Mux, config *config.Config) error {
|
|
||||||
csrfSecret, err := gorilla.GenerateRandomBytes(32)
|
|
||||||
if err != nil {
|
|
||||||
return errors.Wrap(err, "could not generate CSRF secret")
|
|
||||||
}
|
|
||||||
|
|
||||||
csrfMiddleware := csrf.Protect(
|
|
||||||
csrfSecret,
|
|
||||||
csrf.Secure(false),
|
|
||||||
)
|
|
||||||
|
|
||||||
r.Group(func(r chi.Router) {
|
|
||||||
r.Use(csrfMiddleware)
|
|
||||||
|
|
||||||
r.Get("/", serveHomePage)
|
|
||||||
})
|
|
||||||
|
|
||||||
notFoundHandler := r.NotFoundHandler()
|
|
||||||
r.Get("/*", static.Dir(config.HTTP.PublicDir, "", notFoundHandler))
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
@ -1,123 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
set -eo pipefail
|
|
||||||
|
|
||||||
OS_TARGETS=(linux)
|
|
||||||
ARCH_TARGETS=${ARCH_TARGETS:-amd64 arm 386}
|
|
||||||
|
|
||||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
|
|
||||||
PROJECT_DIR="$DIR/../.."
|
|
||||||
|
|
||||||
function build {
|
|
||||||
|
|
||||||
local name=$1
|
|
||||||
local srcdir=$2
|
|
||||||
local os=$3
|
|
||||||
local arch=$4
|
|
||||||
|
|
||||||
local dirname="$name-$os-$arch"
|
|
||||||
local destdir="$PROJECT_DIR/release/$dirname"
|
|
||||||
|
|
||||||
rm -rf "$destdir"
|
|
||||||
mkdir -p "$destdir"
|
|
||||||
|
|
||||||
echo "building $dirname..."
|
|
||||||
|
|
||||||
CGO_ENABLED=0 GOOS="$os" GOARCH="$arch" go build \
|
|
||||||
-mod=vendor \
|
|
||||||
-ldflags="-s -w -X 'main.GitRef=$(current_commit_ref)' -X 'main.ProjectVersion=$(current_version)' -X 'main.BuildDate=$(current_date)'" \
|
|
||||||
-gcflags=-trimpath="${PWD}" \
|
|
||||||
-asmflags=-trimpath="${PWD}" \
|
|
||||||
-o "$destdir/bin/$name" \
|
|
||||||
"$srcdir"
|
|
||||||
|
|
||||||
if [ ! -z "$(which upx)" ]; then
|
|
||||||
upx --best "$destdir/bin/$name"
|
|
||||||
fi
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
function current_date {
|
|
||||||
date '+%Y-%m-%d %H:%M'
|
|
||||||
}
|
|
||||||
|
|
||||||
function current_commit_ref {
|
|
||||||
git log -n 1 --pretty="format:%h"
|
|
||||||
}
|
|
||||||
|
|
||||||
function current_version {
|
|
||||||
local latest_tag=$(git describe --abbrev=0 2>/dev/null)
|
|
||||||
echo ${latest_tag:-0.0.0}
|
|
||||||
}
|
|
||||||
|
|
||||||
function copy {
|
|
||||||
|
|
||||||
local name=$1
|
|
||||||
local os=$2
|
|
||||||
local arch=$3
|
|
||||||
local src=$4
|
|
||||||
local dest=$5
|
|
||||||
|
|
||||||
local dirname="$name-$os-$arch"
|
|
||||||
local destdir="$PROJECT_DIR/release/$dirname"
|
|
||||||
|
|
||||||
echo "copying '$src' to '$destdir/$dest'..."
|
|
||||||
|
|
||||||
mkdir -p "$(dirname $destdir/$dest)"
|
|
||||||
|
|
||||||
cp -rfL $src "$destdir/$dest"
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
function dump_default_conf {
|
|
||||||
# Generate and copy configuration file
|
|
||||||
local command=$1
|
|
||||||
local os=$2
|
|
||||||
local arch=$3
|
|
||||||
local tmp_conf=$(mktemp)
|
|
||||||
|
|
||||||
go run "$PROJECT_DIR/cmd/$command" -dump-config > "$tmp_conf"
|
|
||||||
copy "$command" $os $arch "$tmp_conf" "$command.yml"
|
|
||||||
rm -f "$tmp_conf"
|
|
||||||
}
|
|
||||||
|
|
||||||
function compress {
|
|
||||||
|
|
||||||
local name=$1
|
|
||||||
local os=$2
|
|
||||||
local arch=$3
|
|
||||||
|
|
||||||
local dirname="$name-$os-$arch"
|
|
||||||
local destdir="$PROJECT_DIR/release/$dirname"
|
|
||||||
|
|
||||||
echo "compressing $dirname..."
|
|
||||||
tar -czf "$destdir.tar.gz" -C "$destdir/../" "$dirname"
|
|
||||||
}
|
|
||||||
|
|
||||||
function release_server {
|
|
||||||
|
|
||||||
local os=$1
|
|
||||||
local arch=$2
|
|
||||||
|
|
||||||
build 'server' "$PROJECT_DIR/cmd/server" $os $arch
|
|
||||||
|
|
||||||
dump_default_conf 'server' $os $arch
|
|
||||||
|
|
||||||
copy 'server' $os $arch "$PROJECT_DIR/README.md" "README.md"
|
|
||||||
copy 'server' $os $arch "$PROJECT_DIR/cmd/server/public" "public"
|
|
||||||
copy 'server' $os $arch "$PROJECT_DIR/cmd/server/template" "template"
|
|
||||||
|
|
||||||
compress 'server' $os $arch
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
function main {
|
|
||||||
|
|
||||||
for os in ${OS_TARGETS[@]}; do
|
|
||||||
for arch in ${ARCH_TARGETS[@]}; do
|
|
||||||
release_server $os $arch
|
|
||||||
done
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
main
|
|
@ -1,11 +0,0 @@
|
|||||||
[Unit]
|
|
||||||
Description={{ .ProjectName }}
|
|
||||||
After=network-online.target
|
|
||||||
|
|
||||||
[Service]
|
|
||||||
Type=simple
|
|
||||||
ExecStart=/usr/local/bin/server -workdir /usr/local/share/server -config /etc/server/config.yml
|
|
||||||
Restart=on-failure
|
|
||||||
|
|
||||||
[Install]
|
|
||||||
WantedBy=multi-user.target
|
|
@ -1,13 +0,0 @@
|
|||||||
**/*.go
|
|
||||||
!**/*_test.go
|
|
||||||
data/config.yml
|
|
||||||
!**/rice-box.go
|
|
||||||
modd.conf {
|
|
||||||
prep: make build
|
|
||||||
prep: [ -e data/config.yml ] || ( mkdir -p data && bin/server -dump-config > data/config.yml )
|
|
||||||
daemon: bin/server -workdir "./cmd/server" -config ../../data/config.yml
|
|
||||||
}
|
|
||||||
|
|
||||||
**/*.go {
|
|
||||||
prep: make test
|
|
||||||
}
|
|
@ -1,11 +0,0 @@
|
|||||||
package command
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/urfave/cli/v2"
|
|
||||||
)
|
|
||||||
|
|
||||||
func All() []*cli.Command {
|
|
||||||
return []*cli.Command{
|
|
||||||
newProjectCommand(),
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,276 +0,0 @@
|
|||||||
package command
|
|
||||||
|
|
||||||
import (
|
|
||||||
"io"
|
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
"strings"
|
|
||||||
"text/template"
|
|
||||||
|
|
||||||
"github.com/manifoldco/promptui"
|
|
||||||
|
|
||||||
rice "github.com/GeertJohan/go.rice"
|
|
||||||
"github.com/Masterminds/sprig"
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
"github.com/urfave/cli/v2"
|
|
||||||
)
|
|
||||||
|
|
||||||
func newProjectCommand() *cli.Command {
|
|
||||||
return &cli.Command{
|
|
||||||
Name: "new",
|
|
||||||
Aliases: []string{"n"},
|
|
||||||
Flags: []cli.Flag{
|
|
||||||
&cli.StringFlag{
|
|
||||||
Name: "directory",
|
|
||||||
Aliases: []string{"d"},
|
|
||||||
Value: "./",
|
|
||||||
Usage: "project base directory",
|
|
||||||
Required: false,
|
|
||||||
},
|
|
||||||
&cli.StringFlag{
|
|
||||||
Name: "name",
|
|
||||||
Aliases: []string{"n"},
|
|
||||||
Value: "",
|
|
||||||
Usage: "project name",
|
|
||||||
Required: false,
|
|
||||||
},
|
|
||||||
&cli.StringFlag{
|
|
||||||
Name: "namespace",
|
|
||||||
Aliases: []string{"ns"},
|
|
||||||
Value: "",
|
|
||||||
Usage: "project module namespace",
|
|
||||||
Required: false,
|
|
||||||
},
|
|
||||||
&cli.StringFlag{
|
|
||||||
Name: "type",
|
|
||||||
Aliases: []string{"t"},
|
|
||||||
Value: "",
|
|
||||||
Usage: "project type",
|
|
||||||
Required: false,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Usage: "generate a new project",
|
|
||||||
Action: newProjectAction,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func newProjectAction(c *cli.Context) error {
|
|
||||||
projectLayoutBox, err := rice.FindBox("../.project-layout")
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
destDir := c.String("directory")
|
|
||||||
|
|
||||||
projectName := c.String("name")
|
|
||||||
if projectName == "" {
|
|
||||||
projectName, err = promptForProjectName()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
projectNamespace := c.String("namespace")
|
|
||||||
if projectNamespace == "" {
|
|
||||||
projectNamespace, err = promptForProjectNamespace()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
projectType := c.String("type")
|
|
||||||
if projectType == "" {
|
|
||||||
projectType, err = promptForProjectType()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
data := map[string]interface{}{
|
|
||||||
"ProjectName": projectName,
|
|
||||||
"ProjectType": projectType,
|
|
||||||
"ProjectNamespace": projectNamespace,
|
|
||||||
}
|
|
||||||
|
|
||||||
return copyTemplateDir(projectLayoutBox, projectType, destDir, data, ".gotpl")
|
|
||||||
}
|
|
||||||
|
|
||||||
func promptForProjectName() (string, error) {
|
|
||||||
validate := func(input string) error {
|
|
||||||
if input == "" {
|
|
||||||
return errors.New("Project name cannot be empty")
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
prompt := promptui.Prompt{
|
|
||||||
Label: "Project Name",
|
|
||||||
Validate: validate,
|
|
||||||
}
|
|
||||||
|
|
||||||
return prompt.Run()
|
|
||||||
}
|
|
||||||
|
|
||||||
func promptForProjectNamespace() (string, error) {
|
|
||||||
validate := func(input string) error {
|
|
||||||
if input == "" {
|
|
||||||
return errors.New("Project namespace cannot be empty")
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
prompt := promptui.Prompt{
|
|
||||||
Label: "Project namespace",
|
|
||||||
Validate: validate,
|
|
||||||
}
|
|
||||||
|
|
||||||
return prompt.Run()
|
|
||||||
}
|
|
||||||
|
|
||||||
func promptForProjectType() (string, error) {
|
|
||||||
prompt := promptui.Select{
|
|
||||||
Label: "Project Type",
|
|
||||||
Items: []string{"web"},
|
|
||||||
}
|
|
||||||
|
|
||||||
_, result, err := prompt.Run()
|
|
||||||
|
|
||||||
return result, err
|
|
||||||
}
|
|
||||||
|
|
||||||
func copyFile(box *rice.Box, src, dst string) (err error) {
|
|
||||||
log.Printf("copying file '%s' to '%s'", src, dst)
|
|
||||||
|
|
||||||
in, err := box.Open(src)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer in.Close()
|
|
||||||
|
|
||||||
out, err := os.Create(dst)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
defer func() {
|
|
||||||
if e := out.Close(); e != nil {
|
|
||||||
err = e
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
_, err = io.Copy(out, in)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = out.Sync()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func copyTemplateFile(box *rice.Box, src, dst string, data map[string]interface{}, templateExt string) (err error) {
|
|
||||||
if !strings.HasSuffix(src, templateExt) {
|
|
||||||
return copyFile(box, src, dst)
|
|
||||||
}
|
|
||||||
|
|
||||||
in, err := box.Open(src)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer in.Close()
|
|
||||||
|
|
||||||
templateData, err := ioutil.ReadAll(in)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
tmpl, err := template.New(filepath.Base(src)).Funcs(sprig.TxtFuncMap()).Parse(string(templateData))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
dst = strings.TrimSuffix(dst, templateExt)
|
|
||||||
|
|
||||||
log.Printf("templating file from '%s' to '%s'", src, dst)
|
|
||||||
|
|
||||||
out, err := os.Create(dst)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
defer func() {
|
|
||||||
if e := out.Close(); e != nil {
|
|
||||||
err = e
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
data["SourceFile"] = src
|
|
||||||
data["DestFile"] = dst
|
|
||||||
|
|
||||||
if err := tmpl.Execute(out, data); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func copyTemplateDir(box *rice.Box, baseDir string, dst string, data map[string]interface{}, templateExt string) error {
|
|
||||||
baseDir = filepath.Clean(baseDir)
|
|
||||||
dst = filepath.Clean(dst)
|
|
||||||
|
|
||||||
_, err := os.Stat(dst)
|
|
||||||
if err != nil && !os.IsNotExist(err) {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := os.MkdirAll(dst, 0755); err != nil {
|
|
||||||
return errors.Wrapf(err, "could not create directory '%s'", dst)
|
|
||||||
}
|
|
||||||
|
|
||||||
err = box.Walk(baseDir, func(srcPath string, info os.FileInfo, err error) error {
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if srcPath == baseDir {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
relSrcPath, err := filepath.Rel(baseDir, srcPath)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
dstPath := filepath.Join(dst, relSrcPath)
|
|
||||||
|
|
||||||
if info.IsDir() {
|
|
||||||
log.Printf("creating dir '%s'", dstPath)
|
|
||||||
if err := os.MkdirAll(dstPath, 0755); err != nil {
|
|
||||||
return errors.Wrapf(err, "could not create directory '%s'", dstPath)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
err = copyTemplateFile(box, srcPath, dstPath, data, templateExt)
|
|
||||||
if err != nil {
|
|
||||||
return errors.Wrapf(err, "could not copy file '%s'", srcPath)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return errors.Wrapf(err, "could not walk source directory '%s'", baseDir)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
@ -1,22 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"log"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"gitlab.com/wpetit/goweb/cmd/scaffold/command"
|
|
||||||
|
|
||||||
"github.com/urfave/cli/v2"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
app := &cli.App{
|
|
||||||
Usage: "generate source code for goweb based projects",
|
|
||||||
Commands: command.All(),
|
|
||||||
}
|
|
||||||
|
|
||||||
err := app.Run(os.Args)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
}
|
|
52
cqrs/bus_test.go
Normal file
52
cqrs/bus_test.go
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
package cqrs
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
type testCommandRequest struct {
|
||||||
|
Foo string
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSimpleCommandExec(t *testing.T) {
|
||||||
|
dispatcher := NewDispatcher()
|
||||||
|
|
||||||
|
handlerCalled := false
|
||||||
|
|
||||||
|
handleTestCommand := func(ctx context.Context, cmd Command) error {
|
||||||
|
handlerCalled = true
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
dispatcher.RegisterCommand(
|
||||||
|
MatchCommandRequest(&testCommandRequest{}),
|
||||||
|
CommandHandlerFunc(handleTestCommand),
|
||||||
|
)
|
||||||
|
|
||||||
|
cmd := &testCommandRequest{
|
||||||
|
Foo: "bar",
|
||||||
|
}
|
||||||
|
ctx := context.Background()
|
||||||
|
|
||||||
|
result, err := dispatcher.Exec(ctx, cmd)
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if result == nil {
|
||||||
|
t.Error("result should not be nil")
|
||||||
|
}
|
||||||
|
|
||||||
|
if result.Command() == nil {
|
||||||
|
t.Error("result.Command() should not be nil")
|
||||||
|
}
|
||||||
|
|
||||||
|
if e, g := result.Command().Request(), cmd; e != g {
|
||||||
|
t.Errorf("result.Command().Request(): expected '%v', got '%v'", e, g)
|
||||||
|
}
|
||||||
|
|
||||||
|
if e, g := handlerCalled, true; e != g {
|
||||||
|
t.Errorf("handlerCalled: expected '%v', got '%v'", e, g)
|
||||||
|
}
|
||||||
|
}
|
61
cqrs/command.go
Normal file
61
cqrs/command.go
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
package cqrs
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/google/uuid"
|
||||||
|
)
|
||||||
|
|
||||||
|
type CommandID string
|
||||||
|
|
||||||
|
type CommandRequest interface {
|
||||||
|
}
|
||||||
|
|
||||||
|
type Command interface {
|
||||||
|
ID() CommandID
|
||||||
|
Request() CommandRequest
|
||||||
|
}
|
||||||
|
|
||||||
|
type BaseCommand struct {
|
||||||
|
id CommandID
|
||||||
|
req CommandRequest
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *BaseCommand) ID() CommandID {
|
||||||
|
return c.id
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *BaseCommand) Request() CommandRequest {
|
||||||
|
return c.req
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewBaseCommand(req CommandRequest) *BaseCommand {
|
||||||
|
id := CommandID(uuid.New().String())
|
||||||
|
return &BaseCommand{id, req}
|
||||||
|
}
|
||||||
|
|
||||||
|
type CommandResult interface {
|
||||||
|
Command() Command
|
||||||
|
}
|
||||||
|
|
||||||
|
type BaseCommandResult struct {
|
||||||
|
cmd Command
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *BaseCommandResult) Command() Command {
|
||||||
|
return r.cmd
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewBaseCommandResult(cmd Command) *BaseCommandResult {
|
||||||
|
return &BaseCommandResult{cmd}
|
||||||
|
}
|
||||||
|
|
||||||
|
type CommandHandlerFunc func(context.Context, Command) error
|
||||||
|
|
||||||
|
func (h CommandHandlerFunc) Handle(ctx context.Context, cmd Command) error {
|
||||||
|
return h(ctx, cmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
type CommandHandler interface {
|
||||||
|
Handle(context.Context, Command) error
|
||||||
|
}
|
92
cqrs/dispatcher.go
Normal file
92
cqrs/dispatcher.go
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
package cqrs
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Dispatcher struct {
|
||||||
|
reg *Registry
|
||||||
|
cmdFactory CommandFactory
|
||||||
|
cmdResultFactory CommandResultFactory
|
||||||
|
qryFactory QueryFactory
|
||||||
|
qryResultFactory QueryResultFactory
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Dispatcher) Exec(ctx context.Context, req CommandRequest) (CommandResult, error) {
|
||||||
|
cmd, err := d.cmdFactory(req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
hdlr, mdlwrs, err := d.reg.MatchCommand(cmd)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(mdlwrs) > 0 {
|
||||||
|
for i := len(mdlwrs) - 1; i >= 0; i-- {
|
||||||
|
hdlr = mdlwrs[i](hdlr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := hdlr.Handle(ctx, cmd); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
result, err := d.cmdResultFactory(cmd)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Dispatcher) Query(ctx context.Context, req QueryRequest) (QueryResult, error) {
|
||||||
|
qry, err := d.qryFactory(req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
hdlr, mdlwrs, err := d.reg.MatchQuery(qry)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(mdlwrs) > 0 {
|
||||||
|
for i := len(mdlwrs) - 1; i >= 0; i-- {
|
||||||
|
hdlr = mdlwrs[i](hdlr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
data, err := hdlr.Handle(ctx, qry)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
result, err := d.qryResultFactory(qry, data)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Dispatcher) RegisterCommand(match MatchFunc, hdlr CommandHandler, mdlwrs ...CommandMiddleware) {
|
||||||
|
d.reg.RegisterCommand(match, hdlr, mdlwrs...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Dispatcher) RegisterQuery(match MatchFunc, hdlr QueryHandler, mdlwrs ...QueryMiddleware) {
|
||||||
|
d.reg.RegisterQuery(match, hdlr, mdlwrs...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewDispatcher(funcs ...OptionFunc) *Dispatcher {
|
||||||
|
opt := CreateOption(funcs...)
|
||||||
|
|
||||||
|
return &Dispatcher{
|
||||||
|
reg: NewRegistry(),
|
||||||
|
cmdFactory: opt.CommandFactory,
|
||||||
|
cmdResultFactory: opt.CommandResultFactory,
|
||||||
|
qryFactory: opt.QueryFactory,
|
||||||
|
qryResultFactory: opt.QueryResultFactory,
|
||||||
|
}
|
||||||
|
}
|
9
cqrs/error.go
Normal file
9
cqrs/error.go
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
package cqrs
|
||||||
|
|
||||||
|
import "errors"
|
||||||
|
|
||||||
|
var (
|
||||||
|
ErrHandlerNotFound = errors.New("handler not found")
|
||||||
|
ErrUnexpectedRequest = errors.New("unexpected request")
|
||||||
|
ErrUnexpectedData = errors.New("unexpected data")
|
||||||
|
)
|
33
cqrs/match.go
Normal file
33
cqrs/match.go
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
package cqrs
|
||||||
|
|
||||||
|
import (
|
||||||
|
"reflect"
|
||||||
|
)
|
||||||
|
|
||||||
|
type MatchFunc func(interface{}) (bool, error)
|
||||||
|
|
||||||
|
func MatchCommandRequest(req interface{}) MatchFunc {
|
||||||
|
reqType := reflect.TypeOf(req)
|
||||||
|
|
||||||
|
return func(raw interface{}) (bool, error) {
|
||||||
|
cmd, ok := raw.(Command)
|
||||||
|
if !ok {
|
||||||
|
return false, ErrUnexpectedRequest
|
||||||
|
}
|
||||||
|
|
||||||
|
return reflect.TypeOf(cmd.Request()) == reqType, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func MatchQueryRequest(req interface{}) MatchFunc {
|
||||||
|
reqType := reflect.TypeOf(req)
|
||||||
|
|
||||||
|
return func(raw interface{}) (bool, error) {
|
||||||
|
cmd, ok := raw.(Query)
|
||||||
|
if !ok {
|
||||||
|
return false, ErrUnexpectedRequest
|
||||||
|
}
|
||||||
|
|
||||||
|
return reflect.TypeOf(cmd.Request()) == reqType, nil
|
||||||
|
}
|
||||||
|
}
|
42
cqrs/match_test.go
Normal file
42
cqrs/match_test.go
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
package cqrs
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
type testType struct{}
|
||||||
|
|
||||||
|
func TestMatchCommandRequestType(t *testing.T) {
|
||||||
|
match := MatchCommandRequest(&testType{})
|
||||||
|
|
||||||
|
cmd := NewBaseCommand(&testType{})
|
||||||
|
|
||||||
|
matches, err := match(cmd)
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if e, g := true, matches; e != g {
|
||||||
|
t.Errorf("match(&testType{}): expected '%v', got '%v'", e, g)
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd = NewBaseCommand(nil)
|
||||||
|
|
||||||
|
matches, err = match(cmd)
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if e, g := false, matches; e != g {
|
||||||
|
t.Errorf("match(nil): expected '%v', got '%v'", e, g)
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd = NewBaseCommand("test")
|
||||||
|
|
||||||
|
matches, err = match(cmd)
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if e, g := false, matches; e != g {
|
||||||
|
t.Errorf("match(\"test\"): expected '%v', got '%v'", e, g)
|
||||||
|
}
|
||||||
|
}
|
64
cqrs/middleware_test.go
Normal file
64
cqrs/middleware_test.go
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
package cqrs
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestBasicCommandMiddleware(t *testing.T) {
|
||||||
|
dispatcher := NewDispatcher()
|
||||||
|
|
||||||
|
handlerCalled := false
|
||||||
|
|
||||||
|
handleTestCommand := func(ctx context.Context, cmd Command) error {
|
||||||
|
handlerCalled = true
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
middlewareCalled := false
|
||||||
|
|
||||||
|
commandMiddleware := func(next CommandHandler) CommandHandler {
|
||||||
|
fn := func(ctx context.Context, cmd Command) error {
|
||||||
|
middlewareCalled = true
|
||||||
|
return next.Handle(ctx, cmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
return CommandHandlerFunc(fn)
|
||||||
|
}
|
||||||
|
|
||||||
|
dispatcher.RegisterCommand(
|
||||||
|
MatchCommandRequest(&testCommandRequest{}),
|
||||||
|
CommandHandlerFunc(handleTestCommand),
|
||||||
|
commandMiddleware,
|
||||||
|
)
|
||||||
|
|
||||||
|
cmd := &testCommandRequest{
|
||||||
|
Foo: "bar",
|
||||||
|
}
|
||||||
|
ctx := context.Background()
|
||||||
|
|
||||||
|
result, err := dispatcher.Exec(ctx, cmd)
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if result == nil {
|
||||||
|
t.Error("result should not be nil")
|
||||||
|
}
|
||||||
|
|
||||||
|
if result.Command() == nil {
|
||||||
|
t.Error("result.Command() should not be nil")
|
||||||
|
}
|
||||||
|
|
||||||
|
if e, g := result.Command().Request(), cmd; e != g {
|
||||||
|
t.Errorf("result.Command().Request(): expected '%v', got '%v'", e, g)
|
||||||
|
}
|
||||||
|
|
||||||
|
if e, g := middlewareCalled, true; e != g {
|
||||||
|
t.Errorf("middlewareCalled: expected '%v', got '%v'", e, g)
|
||||||
|
}
|
||||||
|
|
||||||
|
if e, g := handlerCalled, true; e != g {
|
||||||
|
t.Errorf("handlerCalled: expected '%v', got '%v'", e, g)
|
||||||
|
}
|
||||||
|
}
|
86
cqrs/option.go
Normal file
86
cqrs/option.go
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
package cqrs
|
||||||
|
|
||||||
|
type Option struct {
|
||||||
|
CommandFactory CommandFactory
|
||||||
|
QueryFactory QueryFactory
|
||||||
|
CommandResultFactory CommandResultFactory
|
||||||
|
QueryResultFactory QueryResultFactory
|
||||||
|
}
|
||||||
|
|
||||||
|
type CommandFactory func(CommandRequest) (Command, error)
|
||||||
|
type QueryFactory func(QueryRequest) (Query, error)
|
||||||
|
type CommandResultFactory func(Command) (CommandResult, error)
|
||||||
|
type QueryResultFactory func(Query, interface{}) (QueryResult, error)
|
||||||
|
|
||||||
|
type OptionFunc func(*Option)
|
||||||
|
|
||||||
|
func DefaultOption() *Option {
|
||||||
|
funcs := []OptionFunc{
|
||||||
|
WithBaseQueryFactory(),
|
||||||
|
WithBaseCommandFactory(),
|
||||||
|
WithBaseQueryResultFactory(),
|
||||||
|
WithBaseCommandResultFactory(),
|
||||||
|
}
|
||||||
|
|
||||||
|
opt := &Option{}
|
||||||
|
|
||||||
|
for _, fn := range funcs {
|
||||||
|
fn(opt)
|
||||||
|
}
|
||||||
|
|
||||||
|
return opt
|
||||||
|
}
|
||||||
|
|
||||||
|
func CreateOption(funcs ...OptionFunc) *Option {
|
||||||
|
opt := DefaultOption()
|
||||||
|
|
||||||
|
for _, fn := range funcs {
|
||||||
|
fn(opt)
|
||||||
|
}
|
||||||
|
|
||||||
|
return opt
|
||||||
|
}
|
||||||
|
|
||||||
|
func WithCommandFactory(factory CommandFactory) OptionFunc {
|
||||||
|
return func(opt *Option) {
|
||||||
|
opt.CommandFactory = factory
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func WithQueryFactory(factory QueryFactory) OptionFunc {
|
||||||
|
return func(opt *Option) {
|
||||||
|
opt.QueryFactory = factory
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func WithBaseQueryFactory() OptionFunc {
|
||||||
|
return func(opt *Option) {
|
||||||
|
opt.QueryFactory = func(req QueryRequest) (Query, error) {
|
||||||
|
return NewBaseQuery(req), nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func WithBaseCommandFactory() OptionFunc {
|
||||||
|
return func(opt *Option) {
|
||||||
|
opt.CommandFactory = func(req CommandRequest) (Command, error) {
|
||||||
|
return NewBaseCommand(req), nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func WithBaseQueryResultFactory() OptionFunc {
|
||||||
|
return func(opt *Option) {
|
||||||
|
opt.QueryResultFactory = func(qry Query, data interface{}) (QueryResult, error) {
|
||||||
|
return NewBaseQueryResult(qry, data), nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func WithBaseCommandResultFactory() OptionFunc {
|
||||||
|
return func(opt *Option) {
|
||||||
|
opt.CommandResultFactory = func(cmd Command) (CommandResult, error) {
|
||||||
|
return NewBaseCommandResult(cmd), nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
13
cqrs/provider.go
Normal file
13
cqrs/provider.go
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
package cqrs
|
||||||
|
|
||||||
|
import "gitlab.com/wpetit/goweb/service"
|
||||||
|
|
||||||
|
// ServiceProvider returns a service.Provider for the
|
||||||
|
// the cqrs service
|
||||||
|
func ServiceProvider() service.Provider {
|
||||||
|
dispatcher := NewDispatcher()
|
||||||
|
|
||||||
|
return func(container *service.Container) (interface{}, error) {
|
||||||
|
return dispatcher, nil
|
||||||
|
}
|
||||||
|
}
|
66
cqrs/query.go
Normal file
66
cqrs/query.go
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
package cqrs
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/google/uuid"
|
||||||
|
)
|
||||||
|
|
||||||
|
type QueryID string
|
||||||
|
|
||||||
|
type QueryRequest interface{}
|
||||||
|
|
||||||
|
type Query interface {
|
||||||
|
ID() QueryID
|
||||||
|
Request() QueryRequest
|
||||||
|
}
|
||||||
|
|
||||||
|
type BaseQuery struct {
|
||||||
|
id QueryID
|
||||||
|
req QueryRequest
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *BaseQuery) ID() QueryID {
|
||||||
|
return q.id
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *BaseQuery) Request() QueryRequest {
|
||||||
|
return q.req
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewBaseQuery(req QueryRequest) *BaseQuery {
|
||||||
|
id := QueryID(uuid.New().String())
|
||||||
|
return &BaseQuery{id, req}
|
||||||
|
}
|
||||||
|
|
||||||
|
type QueryResult interface {
|
||||||
|
Query() Query
|
||||||
|
Data() interface{}
|
||||||
|
}
|
||||||
|
|
||||||
|
type BaseQueryResult struct {
|
||||||
|
qry Query
|
||||||
|
data interface{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *BaseQueryResult) Query() Query {
|
||||||
|
return r.qry
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *BaseQueryResult) Data() interface{} {
|
||||||
|
return r.data
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewBaseQueryResult(qry Query, data interface{}) *BaseQueryResult {
|
||||||
|
return &BaseQueryResult{qry, data}
|
||||||
|
}
|
||||||
|
|
||||||
|
type QueryHandlerFunc func(context.Context, Query) (interface{}, error)
|
||||||
|
|
||||||
|
func (h QueryHandlerFunc) Handle(ctx context.Context, qry Query) (interface{}, error) {
|
||||||
|
return h(ctx, qry)
|
||||||
|
}
|
||||||
|
|
||||||
|
type QueryHandler interface {
|
||||||
|
Handle(context.Context, Query) (interface{}, error)
|
||||||
|
}
|
68
cqrs/registry.go
Normal file
68
cqrs/registry.go
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
package cqrs
|
||||||
|
|
||||||
|
type CommandMiddleware func(next CommandHandler) CommandHandler
|
||||||
|
type QueryMiddleware func(next QueryHandler) QueryHandler
|
||||||
|
|
||||||
|
type Registry struct {
|
||||||
|
commands []*commandHandler
|
||||||
|
queries []*queryHandler
|
||||||
|
}
|
||||||
|
|
||||||
|
type commandHandler struct {
|
||||||
|
Match MatchFunc
|
||||||
|
Handler CommandHandler
|
||||||
|
Middlewares []CommandMiddleware
|
||||||
|
}
|
||||||
|
|
||||||
|
type queryHandler struct {
|
||||||
|
Match MatchFunc
|
||||||
|
Handler QueryHandler
|
||||||
|
Middlewares []QueryMiddleware
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Registry) MatchCommand(cmd Command) (CommandHandler, []CommandMiddleware, error) {
|
||||||
|
// TODO cache matching to avoid unnecessary ops
|
||||||
|
for _, reg := range r.commands {
|
||||||
|
matches, err := reg.Match(cmd)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if matches {
|
||||||
|
return reg.Handler, reg.Middlewares, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil, nil, ErrHandlerNotFound
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Registry) MatchQuery(qry Query) (QueryHandler, []QueryMiddleware, error) {
|
||||||
|
// TODO cache matching to avoid unnecessary ops
|
||||||
|
for _, reg := range r.queries {
|
||||||
|
matches, err := reg.Match(qry)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if matches {
|
||||||
|
return reg.Handler, reg.Middlewares, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil, nil, ErrHandlerNotFound
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Registry) RegisterCommand(match MatchFunc, hdlr CommandHandler, mdlwrs ...CommandMiddleware) {
|
||||||
|
r.commands = append(r.commands, &commandHandler{match, hdlr, mdlwrs})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Registry) RegisterQuery(match MatchFunc, hdlr QueryHandler, mdlwrs ...QueryMiddleware) {
|
||||||
|
r.queries = append(r.queries, &queryHandler{match, hdlr, mdlwrs})
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewRegistry() *Registry {
|
||||||
|
return &Registry{
|
||||||
|
commands: make([]*commandHandler, 0),
|
||||||
|
queries: make([]*queryHandler, 0),
|
||||||
|
}
|
||||||
|
}
|
34
cqrs/service.go
Normal file
34
cqrs/service.go
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
package cqrs
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"gitlab.com/wpetit/goweb/service"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ServiceName defines the cqrs service name
|
||||||
|
const ServiceName service.Name = "cqrs"
|
||||||
|
|
||||||
|
// From retrieves the cqrs service in the given container
|
||||||
|
func From(container *service.Container) (*Dispatcher, error) {
|
||||||
|
raw, err := container.Service(ServiceName)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrapf(err, "error while retrieving '%s' service", ServiceName)
|
||||||
|
}
|
||||||
|
|
||||||
|
srv, ok := raw.(*Dispatcher)
|
||||||
|
if !ok {
|
||||||
|
return nil, errors.Errorf("retrieved service is not a valid '%s' service", ServiceName)
|
||||||
|
}
|
||||||
|
|
||||||
|
return srv, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Must retrieves the cqrs service in the given container or panic otherwise
|
||||||
|
func Must(container *service.Container) *Dispatcher {
|
||||||
|
service, err := From(container)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return service
|
||||||
|
}
|
1
example/extendable/.gitignore
vendored
Normal file
1
example/extendable/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
/bin
|
11
example/extendable/Makefile
Normal file
11
example/extendable/Makefile
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
build: extension
|
||||||
|
go build -o ./bin/app ./
|
||||||
|
|
||||||
|
extension:
|
||||||
|
go build -o ./bin/myext.so -buildmode=plugin ./myext
|
||||||
|
|
||||||
|
watch:
|
||||||
|
modd
|
||||||
|
|
||||||
|
run:
|
||||||
|
./bin/app
|
23
example/extendable/main.go
Normal file
23
example/extendable/main.go
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"log"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"gitlab.com/wpetit/goweb/extension"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
reg := extension.NewRegistry()
|
||||||
|
ctx := context.Background()
|
||||||
|
|
||||||
|
extensions, err := reg.LoadAll(ctx, "./bin/*.so")
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(errors.WithStack(err))
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, ext := range extensions {
|
||||||
|
log.Printf("Loaded extension '%s', version '%s'", ext.ExtensionName(), ext.ExtensionVersion())
|
||||||
|
}
|
||||||
|
}
|
6
example/extendable/modd.conf
Normal file
6
example/extendable/modd.conf
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
**/*.go
|
||||||
|
modd.conf
|
||||||
|
Makefile {
|
||||||
|
prep: make build
|
||||||
|
prep: make run
|
||||||
|
}
|
12
example/extendable/myext/extension.go
Normal file
12
example/extendable/myext/extension.go
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
type MyExtension struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *MyExtension) ExtensionName() string {
|
||||||
|
return "my.extension"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *MyExtension) ExtensionVersion() string {
|
||||||
|
return "0.0.0"
|
||||||
|
}
|
11
example/extendable/myext/main.go
Normal file
11
example/extendable/myext/main.go
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"gitlab.com/wpetit/goweb/extension"
|
||||||
|
)
|
||||||
|
|
||||||
|
func RegisterExtension(ctx context.Context) (extension.Extension, error) {
|
||||||
|
return &MyExtension{}, nil
|
||||||
|
}
|
8
extension/error.go
Normal file
8
extension/error.go
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
package extension
|
||||||
|
|
||||||
|
import "errors"
|
||||||
|
|
||||||
|
var (
|
||||||
|
ErrInvalidRegisterFunc = errors.New("invalid register func")
|
||||||
|
ErrInvalidExtension = errors.New("invalid extension")
|
||||||
|
)
|
6
extension/extension.go
Normal file
6
extension/extension.go
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
package extension
|
||||||
|
|
||||||
|
type Extension interface {
|
||||||
|
ExtensionName() string
|
||||||
|
ExtensionVersion() string
|
||||||
|
}
|
101
extension/registry.go
Normal file
101
extension/registry.go
Normal file
@ -0,0 +1,101 @@
|
|||||||
|
package extension
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"path/filepath"
|
||||||
|
"plugin"
|
||||||
|
"sync"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Registry struct {
|
||||||
|
extensions map[string]Extension
|
||||||
|
mutex sync.RWMutex
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Registry) Load(ctx context.Context, path string) (Extension, error) {
|
||||||
|
p, err := plugin.Open(path)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.WithStack(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
registerFuncSymbol, err := p.Lookup("RegisterExtension")
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.WithStack(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
register, ok := registerFuncSymbol.(func(context.Context) (Extension, error))
|
||||||
|
if !ok {
|
||||||
|
return nil, errors.WithStack(ErrInvalidRegisterFunc)
|
||||||
|
}
|
||||||
|
|
||||||
|
ext, err := register(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.WithStack(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if ext == nil {
|
||||||
|
return nil, errors.WithStack(ErrInvalidExtension)
|
||||||
|
}
|
||||||
|
|
||||||
|
r.mutex.Lock()
|
||||||
|
r.extensions[ext.ExtensionName()] = ext
|
||||||
|
r.mutex.Unlock()
|
||||||
|
|
||||||
|
return ext, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Registry) LoadAll(ctx context.Context, pattern string) ([]Extension, error) {
|
||||||
|
extensions := make([]Extension, 0)
|
||||||
|
|
||||||
|
matches, err := filepath.Glob(pattern)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.WithStack(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, m := range matches {
|
||||||
|
ext, err := r.Load(ctx, m)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.WithStack(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
extensions = append(extensions, ext)
|
||||||
|
}
|
||||||
|
|
||||||
|
return extensions, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Registry) Extensions() []Extension {
|
||||||
|
r.mutex.RLock()
|
||||||
|
defer r.mutex.RUnlock()
|
||||||
|
|
||||||
|
extensions := make([]Extension, 0, len(r.extensions))
|
||||||
|
for _, e := range r.extensions {
|
||||||
|
extensions = append(extensions, e)
|
||||||
|
}
|
||||||
|
|
||||||
|
return extensions
|
||||||
|
}
|
||||||
|
|
||||||
|
type ExtensionFilterFunc func(ext Extension) bool
|
||||||
|
|
||||||
|
func (r *Registry) Filter(filter ExtensionFilterFunc) []Extension {
|
||||||
|
r.mutex.RLock()
|
||||||
|
defer r.mutex.RUnlock()
|
||||||
|
|
||||||
|
extensions := make([]Extension, 0, len(r.extensions))
|
||||||
|
for _, e := range r.extensions {
|
||||||
|
if filter(e) {
|
||||||
|
extensions = append(extensions, e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return extensions
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewRegistry() *Registry {
|
||||||
|
return &Registry{
|
||||||
|
extensions: make(map[string]Extension),
|
||||||
|
}
|
||||||
|
}
|
14
go.mod
14
go.mod
@ -3,25 +3,17 @@ module gitlab.com/wpetit/goweb
|
|||||||
go 1.12
|
go 1.12
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/GeertJohan/go.rice v1.0.0
|
cdr.dev/slog v1.3.0
|
||||||
github.com/Masterminds/goutils v1.1.0 // indirect
|
github.com/davecgh/go-spew v1.1.1
|
||||||
github.com/Masterminds/semver v1.5.0 // indirect
|
|
||||||
github.com/Masterminds/sprig v2.22.0+incompatible
|
|
||||||
github.com/go-chi/chi v4.0.2+incompatible
|
github.com/go-chi/chi v4.0.2+incompatible
|
||||||
github.com/go-playground/locales v0.12.1 // indirect
|
github.com/go-playground/locales v0.12.1 // indirect
|
||||||
github.com/go-playground/universal-translator v0.16.0 // indirect
|
github.com/go-playground/universal-translator v0.16.0 // indirect
|
||||||
github.com/google/uuid v1.1.1 // indirect
|
github.com/google/uuid v1.1.1
|
||||||
github.com/gorilla/securecookie v1.1.1
|
github.com/gorilla/securecookie v1.1.1
|
||||||
github.com/gorilla/sessions v1.2.0
|
github.com/gorilla/sessions v1.2.0
|
||||||
github.com/huandu/xstrings v1.3.0 // indirect
|
|
||||||
github.com/imdario/mergo v0.3.8 // indirect
|
|
||||||
github.com/leodido/go-urn v1.1.0 // indirect
|
github.com/leodido/go-urn v1.1.0 // indirect
|
||||||
github.com/manifoldco/promptui v0.7.0
|
|
||||||
github.com/mitchellh/copystructure v1.0.0 // indirect
|
|
||||||
github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c
|
github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c
|
||||||
github.com/pkg/errors v0.8.1
|
github.com/pkg/errors v0.8.1
|
||||||
github.com/urfave/cli/v2 v2.1.1
|
|
||||||
golang.org/x/net v0.0.0-20190724013045-ca1201d0de80 // indirect
|
|
||||||
gopkg.in/go-playground/assert.v1 v1.2.1 // indirect
|
gopkg.in/go-playground/assert.v1 v1.2.1 // indirect
|
||||||
gopkg.in/go-playground/validator.v9 v9.29.1
|
gopkg.in/go-playground/validator.v9 v9.29.1
|
||||||
)
|
)
|
||||||
|
237
go.sum
237
go.sum
@ -1,105 +1,244 @@
|
|||||||
|
cdr.dev/slog v1.3.0 h1:MYN1BChIaVEGxdS7I5cpdyMC0+WfJfK8BETAfzfLUGQ=
|
||||||
|
cdr.dev/slog v1.3.0/go.mod h1:C5OL99WyuOK8YHZdYY57dAPN1jK2WJlCdq2VP6xeQns=
|
||||||
|
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||||
|
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||||
|
cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU=
|
||||||
|
cloud.google.com/go v0.44.1/go.mod h1:iSa0KzasP4Uvy3f1mN/7PiObzGgflwredwwASm/v6AU=
|
||||||
|
cloud.google.com/go v0.44.2/go.mod h1:60680Gw3Yr4ikxnPRS/oxxkBccT6SA1yMk63TGekxKY=
|
||||||
|
cloud.google.com/go v0.45.1/go.mod h1:RpBamKRgapWJb87xiFSdk4g1CME7QZg3uwTez+TSTjc=
|
||||||
|
cloud.google.com/go v0.46.3/go.mod h1:a6bKKbmY7er1mI7TEI4lsAkts/mkhTSZK8w33B4RAg0=
|
||||||
|
cloud.google.com/go v0.49.0/go.mod h1:hGvAdzcWNbyuxS3nWhD7H2cIJxjRRTRLQVB0bdputVY=
|
||||||
|
cloud.google.com/go/bigquery v1.0.1/go.mod h1:i/xbL2UlR5RvWAURpBYZTtm/cXjCha9lbfbpx4poX+o=
|
||||||
|
cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7TKLgZqpHYE=
|
||||||
|
cloud.google.com/go/pubsub v1.0.1/go.mod h1:R0Gpsv3s54REJCy4fxDixWD93lHJMoZTyQ2kNxGRt3I=
|
||||||
|
cloud.google.com/go/storage v1.0.0/go.mod h1:IhtSnM/ZTZV8YYJWCY8RULGVqBDmpoyjwiyrjsg+URw=
|
||||||
|
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
|
||||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||||
github.com/GeertJohan/go.incremental v1.0.0 h1:7AH+pY1XUgQE4Y1HcXYaMqAI0m9yrFqo/jt0CW30vsg=
|
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
|
||||||
github.com/GeertJohan/go.incremental v1.0.0/go.mod h1:6fAjUhbVuX1KcMD3c8TEgVUqmo4seqhv0i0kdATSkM0=
|
github.com/GeertJohan/go.incremental v1.0.0/go.mod h1:6fAjUhbVuX1KcMD3c8TEgVUqmo4seqhv0i0kdATSkM0=
|
||||||
github.com/GeertJohan/go.rice v1.0.0 h1:KkI6O9uMaQU3VEKaj01ulavtF7o1fWT7+pk/4voiMLQ=
|
|
||||||
github.com/GeertJohan/go.rice v1.0.0/go.mod h1:eH6gbSOAUv07dQuZVnBmoDP8mgsM1rtixis4Tib9if0=
|
github.com/GeertJohan/go.rice v1.0.0/go.mod h1:eH6gbSOAUv07dQuZVnBmoDP8mgsM1rtixis4Tib9if0=
|
||||||
github.com/Masterminds/goutils v1.1.0 h1:zukEsf/1JZwCMgHiK3GZftabmxiCw4apj3a28RPBiVg=
|
|
||||||
github.com/Masterminds/goutils v1.1.0/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU=
|
|
||||||
github.com/Masterminds/semver v1.5.0 h1:H65muMkzWKEuNDnfl9d70GUjFniHKHRbFPGBuZ3QEww=
|
|
||||||
github.com/Masterminds/semver v1.5.0/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y=
|
|
||||||
github.com/Masterminds/sprig v2.22.0+incompatible h1:z4yfnGrZ7netVz+0EDJ0Wi+5VZCSYp4Z0m2dk6cEM60=
|
|
||||||
github.com/Masterminds/sprig v2.22.0+incompatible/go.mod h1:y6hNFY5UBTIWBxnzTeuNhlNS5hqE0NB0E6fgfo2Br3o=
|
|
||||||
github.com/akavel/rsrc v0.8.0 h1:zjWn7ukO9Kc5Q62DOJCcxGpXC18RawVtYAGdz2aLlfw=
|
|
||||||
github.com/akavel/rsrc v0.8.0/go.mod h1:uLoCtb9J+EyAqh+26kdrTgmzRBFPGOolLWKpdxkKq+c=
|
github.com/akavel/rsrc v0.8.0/go.mod h1:uLoCtb9J+EyAqh+26kdrTgmzRBFPGOolLWKpdxkKq+c=
|
||||||
github.com/chzyer/logex v1.1.10 h1:Swpa1K6QvQznwJRcfTfQJmTE72DqScAa40E+fbHEXEE=
|
github.com/alecthomas/assert v0.0.0-20170929043011-405dbfeb8e38/go.mod h1:r7bzyVFMNntcxPZXK3/+KdruV1H5KSlyVY0gc+NgInI=
|
||||||
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
|
github.com/alecthomas/chroma v0.7.0 h1:z+0HgTUmkpRDRz0SRSdMaqOLfJV4F+N1FPDZUZIDUzw=
|
||||||
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e h1:fY5BOSpyZCqRo5OhCuC+XN+r/bBCmeuuJtjz+bCNIf8=
|
github.com/alecthomas/chroma v0.7.0/go.mod h1:1U/PfCsTALWWYHDnsIQkxEBM0+6LLe0v8+RSVMOwxeY=
|
||||||
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
|
github.com/alecthomas/colour v0.0.0-20160524082231-60882d9e2721/go.mod h1:QO9JBoKquHd+jz9nshCh40fOfO+JzsoXy8qTHF68zU0=
|
||||||
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1 h1:q763qf9huN11kDQavWsoZXJNW3xEE4JJyHa5Q25/sd8=
|
github.com/alecthomas/kong v0.1.17-0.20190424132513-439c674f7ae0/go.mod h1:+inYUSluD+p4L8KdviBSgzcqEjUQOfC5fQDRFuc36lI=
|
||||||
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
|
github.com/alecthomas/kong v0.2.1-0.20190708041108-0548c6b1afae/go.mod h1:+inYUSluD+p4L8KdviBSgzcqEjUQOfC5fQDRFuc36lI=
|
||||||
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY=
|
github.com/alecthomas/kong-hcl v0.1.8-0.20190615233001-b21fea9723c8/go.mod h1:MRgZdU3vrFd05IQ89AxUZ0aYdF39BYoNFa324SodPCA=
|
||||||
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
|
github.com/alecthomas/repr v0.0.0-20180818092828-117648cd9897/go.mod h1:xTS7Pm1pD1mvyM075QCDSRqH6qRLXylzS24ZTpRiSzQ=
|
||||||
github.com/daaku/go.zipexe v1.0.0 h1:VSOgZtH418pH9L16hC/JrgSNJbbAL26pj7lmD1+CGdY=
|
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
||||||
|
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
|
||||||
github.com/daaku/go.zipexe v1.0.0/go.mod h1:z8IiR6TsVLEYKwXAoE/I+8ys/sDkgTzSL0CLnGVd57E=
|
github.com/daaku/go.zipexe v1.0.0/go.mod h1:z8IiR6TsVLEYKwXAoE/I+8ys/sDkgTzSL0CLnGVd57E=
|
||||||
|
github.com/danwakefield/fnmatch v0.0.0-20160403171240-cbb64ac3d964 h1:y5HC9v93H5EPKqaS1UYVg1uYah5Xf51mBfIoWehClUQ=
|
||||||
|
github.com/danwakefield/fnmatch v0.0.0-20160403171240-cbb64ac3d964/go.mod h1:Xd9hchkHSWYkEqJwUGisez3G1QY8Ryz0sdWrLPMGjLk=
|
||||||
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
|
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
|
||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/dlclark/regexp2 v1.1.6/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55kozfMjCc=
|
||||||
|
github.com/dlclark/regexp2 v1.2.0 h1:8sAhBGEM0dRWogWqWyQeIJnxjWO6oIjl8FKqREDsGfk=
|
||||||
|
github.com/dlclark/regexp2 v1.2.0/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55kozfMjCc=
|
||||||
|
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
||||||
|
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
|
||||||
|
github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
|
||||||
|
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
|
||||||
github.com/go-chi/chi v4.0.2+incompatible h1:maB6vn6FqCxrpz4FqWdh4+lwpyZIQS7YEAUcHlgXVRs=
|
github.com/go-chi/chi v4.0.2+incompatible h1:maB6vn6FqCxrpz4FqWdh4+lwpyZIQS7YEAUcHlgXVRs=
|
||||||
github.com/go-chi/chi v4.0.2+incompatible/go.mod h1:eB3wogJHnLi3x/kFX2A+IbTBlXxmMeXJVKy9tTv1XzQ=
|
github.com/go-chi/chi v4.0.2+incompatible/go.mod h1:eB3wogJHnLi3x/kFX2A+IbTBlXxmMeXJVKy9tTv1XzQ=
|
||||||
|
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
|
||||||
github.com/go-playground/locales v0.12.1 h1:2FITxuFt/xuCNP1Acdhv62OzaCiviiE4kotfhkmOqEc=
|
github.com/go-playground/locales v0.12.1 h1:2FITxuFt/xuCNP1Acdhv62OzaCiviiE4kotfhkmOqEc=
|
||||||
github.com/go-playground/locales v0.12.1/go.mod h1:IUMDtCfWo/w/mtMfIE/IG2K+Ey3ygWanZIBtBW0W2TM=
|
github.com/go-playground/locales v0.12.1/go.mod h1:IUMDtCfWo/w/mtMfIE/IG2K+Ey3ygWanZIBtBW0W2TM=
|
||||||
github.com/go-playground/universal-translator v0.16.0 h1:X++omBR/4cE2MNg91AoC3rmGrCjJ8eAeUP/K/EKx4DM=
|
github.com/go-playground/universal-translator v0.16.0 h1:X++omBR/4cE2MNg91AoC3rmGrCjJ8eAeUP/K/EKx4DM=
|
||||||
github.com/go-playground/universal-translator v0.16.0/go.mod h1:1AnU7NaIRDWWzGEKwgtJRd2xk99HeFyHw3yid4rvQIY=
|
github.com/go-playground/universal-translator v0.16.0/go.mod h1:1AnU7NaIRDWWzGEKwgtJRd2xk99HeFyHw3yid4rvQIY=
|
||||||
|
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
|
||||||
|
github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
|
||||||
|
github.com/golang/groupcache v0.0.0-20191027212112-611e8accdfc9 h1:uHTyIjqVhYRhLbJ8nIiOJHkEZZ+5YoOsAbD3sk82NiE=
|
||||||
|
github.com/golang/groupcache v0.0.0-20191027212112-611e8accdfc9/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
|
||||||
|
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
|
||||||
|
github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
|
||||||
|
github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y=
|
||||||
|
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||||
|
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||||
|
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||||
|
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
|
||||||
|
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
|
||||||
|
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
|
||||||
|
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||||
|
github.com/google/go-cmp v0.3.2-0.20191216170541-340f1ebe299e/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||||
|
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
|
||||||
|
github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
|
||||||
|
github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
|
||||||
|
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
|
||||||
github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY=
|
github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY=
|
||||||
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
|
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
|
||||||
|
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
|
||||||
|
github.com/gorilla/csrf v1.6.0/go.mod h1:7tSf8kmjNYr7IWDCYhd3U8Ck34iQ/Yw5CJu7bAkHEGI=
|
||||||
|
github.com/gorilla/handlers v1.4.1/go.mod h1:Qkdc/uu4tH4g6mTK6auzZ766c4CA0Ng8+o/OAirnOIQ=
|
||||||
|
github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
|
||||||
github.com/gorilla/securecookie v1.1.1 h1:miw7JPhV+b/lAHSXz4qd/nN9jRiAFV5FwjeKyCS8BvQ=
|
github.com/gorilla/securecookie v1.1.1 h1:miw7JPhV+b/lAHSXz4qd/nN9jRiAFV5FwjeKyCS8BvQ=
|
||||||
github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4=
|
github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4=
|
||||||
github.com/gorilla/sessions v1.2.0 h1:S7P+1Hm5V/AT9cjEcUD5uDaQSX0OE577aCXgoaKpYbQ=
|
github.com/gorilla/sessions v1.2.0 h1:S7P+1Hm5V/AT9cjEcUD5uDaQSX0OE577aCXgoaKpYbQ=
|
||||||
github.com/gorilla/sessions v1.2.0/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM=
|
github.com/gorilla/sessions v1.2.0/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM=
|
||||||
github.com/huandu/xstrings v1.3.0 h1:gvV6jG9dTgFEncxo+AF7PH6MZXi/vZl25owA/8Dg8Wo=
|
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
|
||||||
github.com/huandu/xstrings v1.3.0/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
|
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
|
||||||
github.com/imdario/mergo v0.3.8 h1:CGgOkSJeqMRmt0D9XLWExdT4m4F1vd3FV3VPt+0VxkQ=
|
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
|
||||||
github.com/imdario/mergo v0.3.8/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
|
|
||||||
github.com/jessevdk/go-flags v1.4.0 h1:4IU2WS7AumrZ/40jfhf4QVDMsQwqA7VEHozFRrGARJA=
|
|
||||||
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
|
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
|
||||||
github.com/juju/ansiterm v0.0.0-20180109212912-720a0952cc2a h1:FaWFmfWdAUKbSCtOU2QjDaorUexogfaMgbipgYATUMU=
|
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
|
||||||
github.com/juju/ansiterm v0.0.0-20180109212912-720a0952cc2a/go.mod h1:UJSiEoRfvx3hP73CvoARgeLjaIOjybY9vj8PUPPFGeU=
|
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
|
||||||
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
|
|
||||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||||
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
|
|
||||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||||
github.com/leodido/go-urn v1.1.0 h1:Sm1gr51B1kKyfD2BlRcLSiEkffoG96g6TPv6eRoEiB8=
|
github.com/leodido/go-urn v1.1.0 h1:Sm1gr51B1kKyfD2BlRcLSiEkffoG96g6TPv6eRoEiB8=
|
||||||
github.com/leodido/go-urn v1.1.0/go.mod h1:+cyI34gQWZcE1eQU7NVgKkkzdXDQHr1dBMtdAPozLkw=
|
github.com/leodido/go-urn v1.1.0/go.mod h1:+cyI34gQWZcE1eQU7NVgKkkzdXDQHr1dBMtdAPozLkw=
|
||||||
github.com/lunixbochs/vtclean v0.0.0-20180621232353-2d01aacdc34a h1:weJVJJRzAJBFRlAiJQROKQs8oC9vOxvm4rZmBBk0ONw=
|
|
||||||
github.com/lunixbochs/vtclean v0.0.0-20180621232353-2d01aacdc34a/go.mod h1:pHhQNgMf3btfWnGBVipUOjRYhoOsdGqdm/+2c2E2WMI=
|
|
||||||
github.com/manifoldco/promptui v0.7.0 h1:3l11YT8tm9MnwGFQ4kETwkzpAwY2Jt9lCrumCUW4+z4=
|
|
||||||
github.com/manifoldco/promptui v0.7.0/go.mod h1:n4zTdgP0vr0S3w7/O/g98U+e0gwLScEXGwov2nIKuGQ=
|
|
||||||
github.com/mattn/go-colorable v0.0.9 h1:UVL0vNpWh04HeJXV0KLcaT7r06gOH2l4OW6ddYRUIY4=
|
|
||||||
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
|
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
|
||||||
github.com/mattn/go-isatty v0.0.4 h1:bnP0vzxcAdeI1zdubAl5PjU6zsERjGZb7raWodagDYs=
|
github.com/mattn/go-colorable v0.1.4 h1:snbPLB8fVfU9iwbbo30TPtbLRzwWu6aJS6Xh4eaaviA=
|
||||||
|
github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
|
||||||
github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
|
github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
|
||||||
github.com/mitchellh/copystructure v1.0.0 h1:Laisrj+bAB6b/yJwB5Bt3ITZhGJdqmxquMKeZ+mmkFQ=
|
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
|
||||||
github.com/mitchellh/copystructure v1.0.0/go.mod h1:SNtv71yrdKgLRyLFxmLdkAbkKEFWgYaq1OVrnRcwhnw=
|
github.com/mattn/go-isatty v0.0.11 h1:FxPOTFNqGkuDUGi3H/qkUbQO4ZiBa2brKq5r0l8TGeM=
|
||||||
github.com/mitchellh/reflectwalk v1.0.0 h1:9D+8oIskB4VJBN5SFlmc27fSlIBZaov1Wpk/IfikLNY=
|
github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE=
|
||||||
github.com/mitchellh/reflectwalk v1.0.0/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
|
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
|
||||||
github.com/nkovacs/streamquote v0.0.0-20170412213628-49af9bddb229 h1:E2B8qYyeSgv5MXpmzZXRNp8IAQ4vjxIjhpAf5hv/tAg=
|
|
||||||
github.com/nkovacs/streamquote v0.0.0-20170412213628-49af9bddb229/go.mod h1:0aYXnNPJ8l7uZxf45rWW1a/uME32OF0rhiYGNQ2oF2E=
|
github.com/nkovacs/streamquote v0.0.0-20170412213628-49af9bddb229/go.mod h1:0aYXnNPJ8l7uZxf45rWW1a/uME32OF0rhiYGNQ2oF2E=
|
||||||
github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c h1:rp5dCmg/yLR3mgFuSOe4oEnDDmGLROTvMragMUXpTQw=
|
github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c h1:rp5dCmg/yLR3mgFuSOe4oEnDDmGLROTvMragMUXpTQw=
|
||||||
github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c/go.mod h1:X07ZCGwUbLaax7L0S3Tw4hpejzu63ZrrQiUe6W0hcy0=
|
github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c/go.mod h1:X07ZCGwUbLaax7L0S3Tw4hpejzu63ZrrQiUe6W0hcy0=
|
||||||
|
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||||
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
|
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
|
||||||
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q=
|
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
||||||
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
|
||||||
github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
|
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
|
||||||
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
|
|
||||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
|
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||||
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
|
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
|
||||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||||
github.com/urfave/cli/v2 v2.1.1 h1:Qt8FeAtxE/vfdrLmR3rxR6JRE0RoVmbXu8+6kZtYU4k=
|
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||||
github.com/urfave/cli/v2 v2.1.1/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ=
|
|
||||||
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
|
|
||||||
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
|
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
|
||||||
github.com/valyala/fasttemplate v1.0.1 h1:tY9CJiPnMXf1ERmG2EyK7gNUd+c6RKGD0IfU8WdUSz8=
|
|
||||||
github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8=
|
github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8=
|
||||||
|
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
|
||||||
|
go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8=
|
||||||
|
go.opencensus.io v0.22.2 h1:75k/FF0Q2YM8QYo07VPddOLBslDt1MZOdEslOHvmzAs=
|
||||||
|
go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
|
||||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 h1:VklqNMn3ovrHsnt90PveolxSbWFaJdECFbxSq0Mqo2M=
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 h1:VklqNMn3ovrHsnt90PveolxSbWFaJdECFbxSq0Mqo2M=
|
||||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
|
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||||
|
golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||||
|
golang.org/x/crypto v0.0.0-20191206172530-e9b2fee46413 h1:ULYEB3JvPRE/IfO+9uO7vKV/xzVTO7XPAwm8xbf4w2g=
|
||||||
|
golang.org/x/crypto v0.0.0-20191206172530-e9b2fee46413/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||||
|
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||||
|
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||||
|
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
|
||||||
|
golang.org/x/exp v0.0.0-20190829153037-c13cbed26979/go.mod h1:86+5VVa7VpoJ4kLfm080zCjGlMRFzhUhsZKEZO7MGek=
|
||||||
|
golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136/go.mod h1:JXzH8nQsPlswgeRAPE3MuO9GYsAcnJvJ4vnMwN/5qkY=
|
||||||
|
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
|
||||||
|
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
|
||||||
|
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
||||||
|
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
|
||||||
|
golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
||||||
|
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||||
|
golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||||
|
golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||||
|
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||||
|
golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE=
|
||||||
|
golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o=
|
||||||
|
golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc=
|
||||||
|
golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY=
|
||||||
|
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||||
|
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||||
|
golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||||
|
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||||
|
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||||
|
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||||
|
golang.org/x/net v0.0.0-20190501004415-9ce7a6920f09/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||||
|
golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||||
|
golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
|
||||||
|
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
golang.org/x/net v0.0.0-20190724013045-ca1201d0de80 h1:Ao/3l156eZf2AW5wK8a7/smtodRU+gha3+BeqJ69lRk=
|
golang.org/x/net v0.0.0-20190724013045-ca1201d0de80 h1:Ao/3l156eZf2AW5wK8a7/smtodRU+gha3+BeqJ69lRk=
|
||||||
golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
|
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||||
|
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||||
|
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||||
|
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
|
golang.org/x/sys v0.0.0-20181128092732-4ed8d59d0b35/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU=
|
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU=
|
||||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
|
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
|
golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20191210023423-ac6580df4449 h1:gSbV7h1NRL2G1xTg/owz62CST1oJBmxy4QpMMregXVQ=
|
||||||
|
golang.org/x/sys v0.0.0-20191210023423-ac6580df4449/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
|
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
|
||||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
|
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
|
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||||
|
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||||
|
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||||
|
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
|
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
|
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
|
||||||
|
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||||
|
golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||||
|
golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||||
|
golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
|
||||||
|
golang.org/x/tools v0.0.0-20190506145303-2d16b83fe98c/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
|
||||||
|
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
|
||||||
|
golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
|
||||||
|
golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
|
||||||
|
golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
|
||||||
|
golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||||
|
golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||||
|
golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||||
|
golang.org/x/tools v0.0.0-20191115202509-3a792d9c32b2/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||||
|
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
|
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
|
||||||
|
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
|
google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE=
|
||||||
|
google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M=
|
||||||
|
google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg=
|
||||||
|
google.golang.org/api v0.9.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg=
|
||||||
|
google.golang.org/api v0.14.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI=
|
||||||
|
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
|
||||||
|
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
|
||||||
|
google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
|
||||||
|
google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0=
|
||||||
|
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
|
||||||
|
google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
|
||||||
|
google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
|
||||||
|
google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
|
||||||
|
google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
|
||||||
|
google.golang.org/genproto v0.0.0-20190801165951-fa694d86fc64/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
|
||||||
|
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
|
||||||
|
google.golang.org/genproto v0.0.0-20190911173649-1774047e7e51/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8=
|
||||||
|
google.golang.org/genproto v0.0.0-20191115194625-c23dd37a84c9/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc=
|
||||||
|
google.golang.org/genproto v0.0.0-20191216164720-4f79533eabd1/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc=
|
||||||
|
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
|
||||||
|
google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38=
|
||||||
|
google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM=
|
||||||
|
google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
|
||||||
|
google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
|
|
||||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
|
||||||
gopkg.in/go-playground/assert.v1 v1.2.1 h1:xoYuJVE7KT85PYWrN730RguIQO0ePzVRfFMXadIrXTM=
|
gopkg.in/go-playground/assert.v1 v1.2.1 h1:xoYuJVE7KT85PYWrN730RguIQO0ePzVRfFMXadIrXTM=
|
||||||
gopkg.in/go-playground/assert.v1 v1.2.1/go.mod h1:9RXL0bg/zibRAgZUYszZSwO/z8Y/a8bDuhia5mkpMnE=
|
gopkg.in/go-playground/assert.v1 v1.2.1/go.mod h1:9RXL0bg/zibRAgZUYszZSwO/z8Y/a8bDuhia5mkpMnE=
|
||||||
gopkg.in/go-playground/validator.v9 v9.29.1 h1:SvGtYmN60a5CVKTOzMSyfzWDeZRxRuGvRQyEAKbw1xc=
|
gopkg.in/go-playground/validator.v9 v9.29.1 h1:SvGtYmN60a5CVKTOzMSyfzWDeZRxRuGvRQyEAKbw1xc=
|
||||||
gopkg.in/go-playground/validator.v9 v9.29.1/go.mod h1:+c9/zcJMFNgbLvly1L1V+PpxWdVbfP1avr/N00E2vyQ=
|
gopkg.in/go-playground/validator.v9 v9.29.1/go.mod h1:+c9/zcJMFNgbLvly1L1V+PpxWdVbfP1avr/N00E2vyQ=
|
||||||
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
|
|
||||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
|
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||||
|
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||||
|
honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||||
|
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||||
|
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
|
||||||
|
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
|
||||||
|
@ -20,7 +20,9 @@ func Example_usage() {
|
|||||||
|
|
||||||
// On expose le service "template" avec l'implémentation
|
// On expose le service "template" avec l'implémentation
|
||||||
// basée sur le moteur de rendu HTML de la librairie standard
|
// basée sur le moteur de rendu HTML de la librairie standard
|
||||||
container.Provide(template.ServiceName, html.ServiceProvider("./templates"))
|
container.Provide(template.ServiceName, html.ServiceProvider(
|
||||||
|
html.NewDirectoryLoader("./templates"),
|
||||||
|
))
|
||||||
|
|
||||||
router := chi.NewRouter()
|
router := chi.NewRouter()
|
||||||
|
|
||||||
|
109
logger/logger.go
Normal file
109
logger/logger.go
Normal file
@ -0,0 +1,109 @@
|
|||||||
|
package logger
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"io"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
|
"cdr.dev/slog/sloggers/slogjson"
|
||||||
|
|
||||||
|
"cdr.dev/slog/sloggers/sloghuman"
|
||||||
|
|
||||||
|
"cdr.dev/slog"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Format string
|
||||||
|
|
||||||
|
const (
|
||||||
|
FormatHuman Format = "human"
|
||||||
|
FormatJSON Format = "json"
|
||||||
|
)
|
||||||
|
|
||||||
|
var defaultLogger slog.Logger // nolint: gochecknoglobals
|
||||||
|
|
||||||
|
type Field = slog.Field
|
||||||
|
type Map = slog.Map
|
||||||
|
type Level = slog.Level
|
||||||
|
|
||||||
|
const (
|
||||||
|
LevelCritical Level = slog.LevelCritical
|
||||||
|
LevelError Level = slog.LevelError
|
||||||
|
LevelWarn Level = slog.LevelWarn
|
||||||
|
LevelInfo Level = slog.LevelInfo
|
||||||
|
LevelDebug Level = slog.LevelDebug
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() { // nolint: gochecknoinits
|
||||||
|
defaultLogger = Make(FormatHuman, os.Stdout)
|
||||||
|
}
|
||||||
|
|
||||||
|
func Make(f Format, w io.Writer) slog.Logger {
|
||||||
|
var logger slog.Logger
|
||||||
|
|
||||||
|
switch f {
|
||||||
|
case FormatHuman:
|
||||||
|
logger = sloghuman.Make(w)
|
||||||
|
case FormatJSON:
|
||||||
|
logger = slogjson.Make(w)
|
||||||
|
default:
|
||||||
|
panic(errors.Errorf("unknown logger format '%s'", f))
|
||||||
|
}
|
||||||
|
|
||||||
|
return logger
|
||||||
|
}
|
||||||
|
|
||||||
|
func Debug(ctx context.Context, msg string, fields ...Field) {
|
||||||
|
slog.Helper()
|
||||||
|
defaultLogger.Debug(ctx, msg, fields...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func Info(ctx context.Context, msg string, fields ...Field) {
|
||||||
|
slog.Helper()
|
||||||
|
defaultLogger.Info(ctx, msg, fields...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func Warn(ctx context.Context, msg string, fields ...Field) {
|
||||||
|
slog.Helper()
|
||||||
|
defaultLogger.Warn(ctx, msg, fields...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func Error(ctx context.Context, msg string, fields ...Field) {
|
||||||
|
slog.Helper()
|
||||||
|
defaultLogger.Error(ctx, msg, fields...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func Critical(ctx context.Context, msg string, fields ...Field) {
|
||||||
|
slog.Helper()
|
||||||
|
defaultLogger.Critical(ctx, msg, fields...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func Fatal(ctx context.Context, msg string, fields ...Field) {
|
||||||
|
slog.Helper()
|
||||||
|
defaultLogger.Fatal(ctx, msg, fields...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func F(name string, value interface{}) Field {
|
||||||
|
return slog.F(name, value)
|
||||||
|
}
|
||||||
|
|
||||||
|
func M(fields ...Field) Map {
|
||||||
|
return slog.M(fields...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func E(err error) Field {
|
||||||
|
return slog.Error(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func SetLevel(level Level) {
|
||||||
|
defaultLogger = defaultLogger.Leveled(level)
|
||||||
|
}
|
||||||
|
|
||||||
|
func SetFormat(format Format) {
|
||||||
|
defaultLogger = Make(format, os.Stdout)
|
||||||
|
}
|
||||||
|
|
||||||
|
func With(ctx context.Context, fields ...Field) context.Context {
|
||||||
|
return slog.With(ctx, fields...)
|
||||||
|
}
|
@ -41,3 +41,9 @@ func Must(ctx context.Context) *service.Container {
|
|||||||
func ServiceContainer(container *service.Container) goweb.Middleware {
|
func ServiceContainer(container *service.Container) goweb.Middleware {
|
||||||
return middleware.WithValue(KeyServiceContainer, container)
|
return middleware.WithValue(KeyServiceContainer, container)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WithContainer returns a new context.Context with the given *service.Container
|
||||||
|
// attached.
|
||||||
|
func WithContainer(ctx context.Context, container *service.Container) context.Context {
|
||||||
|
return context.WithValue(ctx, KeyServiceContainer, container)
|
||||||
|
}
|
||||||
|
12
modd.conf
12
modd.conf
@ -1,13 +1,3 @@
|
|||||||
**/*.go
|
**/*.go {
|
||||||
!**/rice-box.go {
|
|
||||||
prep: make build
|
|
||||||
}
|
|
||||||
|
|
||||||
cmd/scaffold/.project-layout/** {
|
|
||||||
prep: make build
|
|
||||||
}
|
|
||||||
|
|
||||||
**/*.go
|
|
||||||
!**/rice-box.go {
|
|
||||||
prep: make test
|
prep: make test
|
||||||
}
|
}
|
@ -1,6 +1,7 @@
|
|||||||
package template
|
package template
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
@ -13,6 +14,7 @@ const ServiceName service.Name = "template"
|
|||||||
// Service is a templating service
|
// Service is a templating service
|
||||||
type Service interface {
|
type Service interface {
|
||||||
RenderPage(w http.ResponseWriter, templateName string, data interface{}) error
|
RenderPage(w http.ResponseWriter, templateName string, data interface{}) error
|
||||||
|
Render(w io.Writer, templateName string, data interface{}) error
|
||||||
}
|
}
|
||||||
|
|
||||||
// From retrieves the template service in the given container
|
// From retrieves the template service in the given container
|
||||||
|
56
template/html/loader.go
Normal file
56
template/html/loader.go
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
package html
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io/ioutil"
|
||||||
|
"path/filepath"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Loader interface {
|
||||||
|
Load(*TemplateService) error
|
||||||
|
}
|
||||||
|
|
||||||
|
type DirectoryLoader struct {
|
||||||
|
rootDir string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *DirectoryLoader) Load(srv *TemplateService) error {
|
||||||
|
blockFiles, err := filepath.Glob(filepath.Join(l.rootDir, "blocks", "*.tmpl"))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, f := range blockFiles {
|
||||||
|
blockContent, err := ioutil.ReadFile(f)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
blockName := filepath.Base(f)
|
||||||
|
srv.AddBlock(blockName, string(blockContent))
|
||||||
|
}
|
||||||
|
|
||||||
|
layoutFiles, err := filepath.Glob(filepath.Join(l.rootDir, "layouts", "*.tmpl"))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Generate our templates map from our layouts/ and blocks/ directories
|
||||||
|
for _, f := range layoutFiles {
|
||||||
|
templateData, err := ioutil.ReadFile(f)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
templateName := filepath.Base(f)
|
||||||
|
|
||||||
|
if err := srv.LoadLayout(templateName, string(templateData)); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewDirectoryLoader(rootDir string) *DirectoryLoader {
|
||||||
|
return &DirectoryLoader{rootDir}
|
||||||
|
}
|
@ -6,6 +6,7 @@ import "html/template"
|
|||||||
type Options struct {
|
type Options struct {
|
||||||
Helpers template.FuncMap
|
Helpers template.FuncMap
|
||||||
PoolSize int
|
PoolSize int
|
||||||
|
DevMode bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// OptionFunc configures options for the template service
|
// OptionFunc configures options for the template service
|
||||||
@ -48,6 +49,14 @@ func WithPoolSize(size int) OptionFunc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WithDevMode configures the template service
|
||||||
|
// to use the development mode (auto reload of templates).
|
||||||
|
func WithDevMode(enabled bool) OptionFunc {
|
||||||
|
return func(opts *Options) {
|
||||||
|
opts.DevMode = enabled
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func defaultOptions() *Options {
|
func defaultOptions() *Options {
|
||||||
options := &Options{}
|
options := &Options{}
|
||||||
funcs := []OptionFunc{
|
funcs := []OptionFunc{
|
||||||
|
@ -4,9 +4,9 @@ import "gitlab.com/wpetit/goweb/service"
|
|||||||
|
|
||||||
// ServiceProvider returns a service.Provider for the
|
// ServiceProvider returns a service.Provider for the
|
||||||
// the HTML template service implementation
|
// the HTML template service implementation
|
||||||
func ServiceProvider(templateDir string, funcs ...OptionFunc) service.Provider {
|
func ServiceProvider(loader Loader, funcs ...OptionFunc) service.Provider {
|
||||||
templateService := NewTemplateService(funcs...)
|
templateService := NewTemplateService(loader, funcs...)
|
||||||
err := templateService.LoadTemplatesDir(templateDir)
|
err := templateService.Load()
|
||||||
return func(container *service.Container) (interface{}, error) {
|
return func(container *service.Container) (interface{}, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -1,90 +1,79 @@
|
|||||||
package html
|
package html
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"errors"
|
||||||
"html/template"
|
"html/template"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"path/filepath"
|
"sync"
|
||||||
|
|
||||||
"github.com/oxtoacart/bpool"
|
"github.com/oxtoacart/bpool"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
ErrLayoutNotFound = errors.New("layout not found")
|
||||||
|
)
|
||||||
|
|
||||||
// TemplateService is a template/html based templating service
|
// TemplateService is a template/html based templating service
|
||||||
type TemplateService struct {
|
type TemplateService struct {
|
||||||
templates map[string]*template.Template
|
mutex sync.RWMutex
|
||||||
|
blocks map[string]string
|
||||||
|
layouts map[string]*template.Template
|
||||||
|
loader Loader
|
||||||
pool *bpool.BufferPool
|
pool *bpool.BufferPool
|
||||||
helpers template.FuncMap
|
helpers template.FuncMap
|
||||||
|
devMode bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *TemplateService) LoadLayout(name string, layout string, blocks []string) error {
|
func (t *TemplateService) AddBlock(name string, blockContent string) {
|
||||||
|
t.mutex.Lock()
|
||||||
|
defer t.mutex.Unlock()
|
||||||
|
|
||||||
|
t.blocks[name] = blockContent
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *TemplateService) LoadLayout(name string, layoutContent string) error {
|
||||||
tmpl := template.New(name)
|
tmpl := template.New(name)
|
||||||
tmpl.Funcs(t.helpers)
|
tmpl.Funcs(t.helpers)
|
||||||
|
|
||||||
for _, b := range blocks {
|
t.mutex.RLock()
|
||||||
|
for _, b := range t.blocks {
|
||||||
if _, err := tmpl.Parse(b); err != nil {
|
if _, err := tmpl.Parse(b); err != nil {
|
||||||
|
t.mutex.RUnlock()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
t.mutex.RUnlock()
|
||||||
|
|
||||||
tmpl, err := tmpl.Parse(layout)
|
tmpl, err := tmpl.Parse(layoutContent)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
t.templates[name] = tmpl
|
t.mutex.Lock()
|
||||||
|
t.layouts[name] = tmpl
|
||||||
|
t.mutex.Unlock()
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// LoadTemplatesDir loads the templates used by the service
|
// Load parses templates via the configured template loader.
|
||||||
func (t *TemplateService) LoadTemplatesDir(templatesDir string) error {
|
func (t *TemplateService) Load() error {
|
||||||
layoutFiles, err := filepath.Glob(filepath.Join(templatesDir, "layouts", "*.tmpl"))
|
return t.loader.Load(t)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
blockFiles, err := filepath.Glob(filepath.Join(templatesDir, "blocks", "*.tmpl"))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
blockTemplates := make([]string, 0, len(blockFiles))
|
|
||||||
|
|
||||||
for _, f := range blockFiles {
|
|
||||||
templateData, err := ioutil.ReadFile(f)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
blockTemplates = append(blockTemplates, string(templateData))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Generate our templates map from our layouts/ and blocks/ directories
|
|
||||||
for _, f := range layoutFiles {
|
|
||||||
templateData, err := ioutil.ReadFile(f)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
templateName := filepath.Base(f)
|
|
||||||
|
|
||||||
if err := t.LoadLayout(templateName, string(templateData), blockTemplates); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// RenderPage renders a template to the given http.ResponseWriter
|
// RenderPage renders a template to the given http.ResponseWriter
|
||||||
func (t *TemplateService) RenderPage(w http.ResponseWriter, templateName string, data interface{}) error {
|
func (t *TemplateService) RenderPage(w http.ResponseWriter, templateName string, data interface{}) error {
|
||||||
|
if t.devMode {
|
||||||
|
if err := t.loader.Load(t); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Ensure the template exists in the map.
|
// Ensure the template exists in the map.
|
||||||
tmpl, ok := t.templates[templateName]
|
tmpl, ok := t.layouts[templateName]
|
||||||
if !ok {
|
if !ok {
|
||||||
return fmt.Errorf("the template '%s' does not exist", templateName)
|
return ErrLayoutNotFound
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a buffer to temporarily write to and check if any errors were encountered.
|
// Create a buffer to temporarily write to and check if any errors were encountered.
|
||||||
@ -102,15 +91,45 @@ func (t *TemplateService) RenderPage(w http.ResponseWriter, templateName string,
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Render renders a layout to the given io.Writer.
|
||||||
|
func (t *TemplateService) Render(w io.Writer, layoutName string, data interface{}) error {
|
||||||
|
if t.devMode {
|
||||||
|
if err := t.loader.Load(t); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ensure the template exists in the map.
|
||||||
|
tmpl, ok := t.layouts[layoutName]
|
||||||
|
if !ok {
|
||||||
|
return ErrLayoutNotFound
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a buffer to temporarily write to and check if any errors were encountered.
|
||||||
|
buf := t.pool.Get()
|
||||||
|
defer t.pool.Put(buf)
|
||||||
|
|
||||||
|
if err := tmpl.ExecuteTemplate(buf, layoutName, data); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err := buf.WriteTo(w)
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// NewTemplateService returns a new Service
|
// NewTemplateService returns a new Service
|
||||||
func NewTemplateService(funcs ...OptionFunc) *TemplateService {
|
func NewTemplateService(loader Loader, funcs ...OptionFunc) *TemplateService {
|
||||||
options := defaultOptions()
|
options := defaultOptions()
|
||||||
for _, f := range funcs {
|
for _, f := range funcs {
|
||||||
f(options)
|
f(options)
|
||||||
}
|
}
|
||||||
return &TemplateService{
|
return &TemplateService{
|
||||||
templates: make(map[string]*template.Template),
|
blocks: make(map[string]string),
|
||||||
|
layouts: make(map[string]*template.Template),
|
||||||
pool: bpool.NewBufferPool(options.PoolSize),
|
pool: bpool.NewBufferPool(options.PoolSize),
|
||||||
helpers: options.Helpers,
|
helpers: options.Helpers,
|
||||||
|
loader: loader,
|
||||||
|
devMode: options.DevMode,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user