1
0
Fork 0

Commits vergleichen

..

8 Commits
v0.5.5 ... main

Autor SHA1 Nachricht Datum
5717ec7a91 fixed spelling error 2023-03-25 09:41:59 +01:00
9ac6b96eee server now waits on teardown sites 2023-03-25 09:41:46 +01:00
818560df17 optimized the inerrupt handling 2022-11-19 19:23:39 +01:00
4aa50328f2 changed the format of the xid to string 2022-11-19 19:04:36 +01:00
b71fcb8fa2 clean up of the go.mod and go.sum 2022-11-19 15:00:56 +01:00
f8a7689fea added the uuid type for conversion
i decided to use github.com/gofrs/uuid, since it implements uuidv7
2022-11-19 13:41:28 +01:00
1d647c7d00 Added better error handling 2022-11-19 11:28:27 +01:00
2326ceb32e fixed the SetupMigrator 2022-11-19 11:05:06 +01:00
5 geänderte Dateien mit 57 neuen und 47 gelöschten Zeilen

33
go.mod
Datei anzeigen

@ -6,39 +6,35 @@ require (
github.com/crewjam/saml v0.4.8
github.com/flosch/pongo2/v6 v6.0.0
github.com/gin-gonic/gin v1.8.1
github.com/go-ap/jsonld v0.0.0-20221030091449-f2a191312c73
github.com/golang-jwt/jwt/v4 v4.4.2
github.com/google/uuid v1.3.0
github.com/jackc/pgx-gofrs-uuid v0.0.0-20220402203838-5fdaf7ddb8a2
github.com/jackc/pgx/v5 v5.1.1
github.com/jackc/tern/v2 v2.0.0-beta.3
github.com/rs/xid v1.4.0
github.com/rs/zerolog v1.28.0
)
require (
github.com/Masterminds/semver/v3 v3.1.1 // indirect
github.com/Masterminds/sprig/v3 v3.2.2 // indirect
github.com/jackc/puddle/v2 v2.1.2 // indirect
github.com/shopspring/decimal v1.3.1 // indirect
github.com/spf13/cast v1.5.0 // indirect
go.uber.org/atomic v1.10.0 // indirect
golang.org/x/sync v0.1.0 // indirect
go.sebtobie.de/generic v1.0.1
)
require (
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/semver/v3 v3.1.1 // indirect
github.com/Masterminds/sprig/v3 v3.2.2 // indirect
github.com/beevik/etree v1.1.0 // indirect
github.com/crewjam/httperr v0.2.0 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-ap/jsonld v0.0.0-20221030091449-f2a191312c73
github.com/go-playground/locales v0.14.0 // indirect
github.com/go-playground/universal-translator v0.18.0 // indirect
github.com/go-playground/validator/v10 v10.11.1 // indirect
github.com/goccy/go-json v0.9.11 // indirect
github.com/huandu/xstrings v1.3.3 // indirect
github.com/gofrs/uuid v4.2.0+incompatible // indirect
github.com/huandu/xstrings v1.3.2 // indirect
github.com/imdario/mergo v0.3.13 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b // indirect
github.com/jackc/pgx/v5 v5.1.0
github.com/jackc/tern/v2 v2.0.0-beta.3
github.com/jonboulle/clockwork v0.3.0 // indirect
github.com/jackc/puddle/v2 v2.1.2 // indirect
github.com/jonboulle/clockwork v0.2.2 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/leodido/go-urn v1.2.1 // indirect
github.com/mattermost/xml-roundtrip-validator v0.1.0 // indirect
@ -51,14 +47,15 @@ require (
github.com/pelletier/go-toml/v2 v2.0.6 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/russellhaering/goxmldsig v1.1.1 // indirect
github.com/shopspring/decimal v1.3.1 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/ugorji/go/codec v1.2.7 // indirect
go.sebtobie.de/generic v1.0.1
go.uber.org/atomic v1.10.0 // indirect
golang.org/x/crypto v0.3.0 // indirect
golang.org/x/net v0.2.0 // indirect
golang.org/x/sync v0.0.0-20220923202941-7f9b1623fab7 // indirect
golang.org/x/sys v0.2.0 // indirect
golang.org/x/text v0.4.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)
retract [v0.0.0, v0.5.1] // bugs in the whole module that result in crashes

24
go.sum
Datei anzeigen

@ -35,6 +35,8 @@ github.com/go-playground/validator/v10 v10.11.1/go.mod h1:i+3WkQ1FvaUjjxh1kSvIA4
github.com/goccy/go-json v0.9.11 h1:/pAaQDLHEoCq/5FFmSKBswWmK6H0e8g4159Kc/X/nqk=
github.com/goccy/go-json v0.9.11/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/gofrs/uuid v4.2.0+incompatible h1:yyYWMnhkhrKwwr8gAOcOCYxOOscHgDS9yZgBrnJfGa0=
github.com/gofrs/uuid v4.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
github.com/golang-jwt/jwt/v4 v4.4.2 h1:rcc4lwaZgFMCZ5jxF9ABolDcIHdBytAFgqFPbSJQAYs=
github.com/golang-jwt/jwt/v4 v4.4.2/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
@ -46,8 +48,8 @@ github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/huandu/xstrings v1.3.1/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
github.com/huandu/xstrings v1.3.3 h1:/Gcsuc1x8JVbJ9/rlye4xZnVAbEkGauT8lbebqcQws4=
github.com/huandu/xstrings v1.3.3/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
github.com/huandu/xstrings v1.3.2 h1:L18LIDzqlW6xN2rEkpdV8+oL/IXWJ1APd+vsdYy4Wdw=
github.com/huandu/xstrings v1.3.2/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
github.com/imdario/mergo v0.3.11/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
github.com/imdario/mergo v0.3.13 h1:lFzP57bqS/wsqKssCGmtLAb8A0wKjLGrve2q3PPVcBk=
github.com/imdario/mergo v0.3.13/go.mod h1:4lJ1jqUDcsbIECGy0RUJAXNIhg+6ocWgb1ALK2O4oXg=
@ -55,15 +57,16 @@ github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsI
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b h1:C8S2+VttkHFdOOCXJe+YGfa4vHYwlt4Zx+IVXQ97jYg=
github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b/go.mod h1:vsD4gTJCa9TptPL8sPkXrLZ+hDuNrZCnj29CQpr4X1E=
github.com/jackc/pgx/v5 v5.1.0 h1:Z7pLKUb65HK6m18No8GGKT87K34NhIIEHa86rRdjxbU=
github.com/jackc/pgx/v5 v5.1.0/go.mod h1:Ptn7zmohNsWEsdxRawMzk3gaKma2obW+NWTnKa0S4nk=
github.com/jackc/pgx-gofrs-uuid v0.0.0-20220402203838-5fdaf7ddb8a2 h1:6qEGnCP4zC+VNPCcb3aHpK4vB51mdE0yyjreAEfjI9c=
github.com/jackc/pgx-gofrs-uuid v0.0.0-20220402203838-5fdaf7ddb8a2/go.mod h1:qNQYZ2L+Xpfoj0yU0Moom/Hlbre7mQLS3b006rVArMs=
github.com/jackc/pgx/v5 v5.1.1 h1:pZD79K1SYv8wc2HmCQA6VdmRQi7/OtCfv9bM3WAXUYA=
github.com/jackc/pgx/v5 v5.1.1/go.mod h1:Ptn7zmohNsWEsdxRawMzk3gaKma2obW+NWTnKa0S4nk=
github.com/jackc/puddle/v2 v2.1.2 h1:0f7vaaXINONKTsxYDn4otOAiJanX/BMeAtY//BXqzlg=
github.com/jackc/puddle/v2 v2.1.2/go.mod h1:2lpufsF5mRHO6SuZkm0fNYxM6SWHfvyFj62KwNzgels=
github.com/jackc/tern/v2 v2.0.0-beta.3 h1:eLC0C8KgIHVkcm7fJvrG4B1gTjRO1xkGN1g9gQBoh3k=
github.com/jackc/tern/v2 v2.0.0-beta.3/go.mod h1:JC+qkR3EMEgATsTKdYojLBizn2gl4jWQmwqbUxYbA8U=
github.com/jonboulle/clockwork v0.2.2 h1:UOGuzwb1PwsrDAObMuhUnj0p5ULPj8V/xJ7Kx9qUBdQ=
github.com/jonboulle/clockwork v0.2.2/go.mod h1:Pkfl5aHPm1nk2H9h0bjmnJD/BcgbGXUBGnn1kMkgxc8=
github.com/jonboulle/clockwork v0.3.0 h1:9BSCMi8C+0qdApAp4auwX0RkLGUjs956h0EkuQymUhg=
github.com/jonboulle/clockwork v0.3.0/go.mod h1:Pkfl5aHPm1nk2H9h0bjmnJD/BcgbGXUBGnn1kMkgxc8=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
@ -95,8 +98,6 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/pelletier/go-toml/v2 v2.0.5 h1:ipoSadvV8oGUjnUbMub59IDPPwfxF694nG/jwbMiyQg=
github.com/pelletier/go-toml/v2 v2.0.5/go.mod h1:OMHamSCAODeSsVrwwvcJOaoN0LIUIaFVNZzmWyNfXas=
github.com/pelletier/go-toml/v2 v2.0.6 h1:nrzqCb7j9cDFj2coyLNLaZuJTLjWjlaz6nvTvIwycIU=
github.com/pelletier/go-toml/v2 v2.0.6/go.mod h1:eumQOmlWiOPt5WriQQqoM5y18pDHwha2N+QD+EUNTek=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
@ -130,7 +131,6 @@ github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
@ -146,16 +146,14 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk
golang.org/x/crypto v0.0.0-20200414173820-0848c9571904/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.0.0-20220128200615-198e4374d7ed/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.2.0 h1:BRXPfhNivWL5Yq0BGQ39a2sW6t44aODpfxkWjYdzewE=
golang.org/x/crypto v0.2.0/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4=
golang.org/x/crypto v0.3.0 h1:a06MkbcxBrEFc0w0QIZWXrH/9cCX6KJyWbBOIwAn+7A=
golang.org/x/crypto v0.3.0/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.2.0 h1:sZfSu1wtKLGlWI4ZZayP0ck9Y73K1ynO6gqzTdBVdPU=
golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY=
golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220923202941-7f9b1623fab7 h1:ZrnxWX62AgTKOSagEqxvb3ffipvEDX2pl7E1TdqLqIc=
golang.org/x/sync v0.0.0-20220923202941-7f9b1623fab7/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=

13
http.go
Datei anzeigen

@ -188,11 +188,12 @@ func (s *Server) Use(m ...gin.HandlerFunc) {
}
// Stop Shuts the Server down
func (s *Server) Stop(ctx context.Context) {
log.Info().Err(s.http.Shutdown(ctx)).Msg("Server Shut down.")
for _, s := range s.sites {
func (server *Server) Stop(ctx context.Context) {
log.Info().Err(server.http.Shutdown(ctx)).Msg("Server Shut down.")
for _, s := range server.sites {
if ts, ok := s.(TeardownSite); ok {
ts.Teardown()
server.routines.Done()
}
}
}
@ -238,7 +239,7 @@ func unequal[T comparable](i T) func(t T) bool {
// 3. Middleware.Sites
// 4. Site.Setup
func (s *Server) Setup() {
log.Info().Msg("Perparing server for start")
log.Info().Msg("Preparing server for start")
var (
router *gin.Engine
found bool
@ -304,6 +305,10 @@ func (s *Server) Setup() {
log.Error().Err(err).Msgf("Failed to setup site with config %s", cfg)
}
}
if _, ok := site.(TeardownSite); ok {
log.Trace().Msg("Added teardownsite to the sg")
s.routines.Add(1)
}
}
for _, m := range s.advmiddleware {
if psm, ok := m.(middleware.PostSetupMiddleware); ok {

Datei anzeigen

@ -14,6 +14,8 @@ import (
"github.com/jackc/tern/v2/migrate"
"github.com/rs/zerolog/log"
"go.sebtobie.de/httpserver/middleware"
uuid "github.com/jackc/pgx-gofrs-uuid"
)
// ContextKey is the key that is used in a gin.Context to get the Middleware
@ -29,7 +31,10 @@ var _ middleware.PostSetupMiddleware = &Middleware{}
// GetConnection is an simple helper function that returns an connection to the db
func GetConnection(c *gin.Context, db string) (*pgxpool.Conn, error) {
if co, ok := c.Get(ContextKey); ok {
return co.(ConnGet)(db), nil
if cg, ok := co.(ConnGet); ok {
return cg(db), nil
}
return nil, fmt.Errorf("Failed to convert the method. %T != ConnGet", co)
}
return nil, errors.New("No db.Middleware set up. ")
}
@ -58,15 +63,15 @@ func (m *Middleware) AddDB(name, uri string) (err error) {
var (
db *pgxpool.Pool
)
if err != nil {
log.Error().Err(err).Msg("Could not open the database")
return err
}
db, err = pgxpool.New(context.TODO(), uri)
if err != nil {
log.Error().Err(err).Msg("Could not open the database")
return err
}
db.Config().AfterConnect = func(_ context.Context, c *pgx.Conn) error {
uuid.Register(c.TypeMap())
return nil
}
m.lock.Lock()
defer m.lock.Unlock()
if olddb, found := m.databases[name]; found {
@ -101,7 +106,7 @@ func (m *Middleware) GetConn(name string) *pgxpool.Conn {
// Gin is the Entrypoint for Gin.
func (m *Middleware) Gin(c *gin.Context) {
c.Set(ContextKey, m.GetConn)
c.Set(ContextKey, ConnGet(m.GetConn))
}
// Setup adds the connections from the configfile into the middleware
@ -188,7 +193,7 @@ func SetupMigrator(prefix string, connection *pgx.Conn, migrations fs.FS) (mig *
mig, err = migrate.NewMigratorEx(
context.TODO(),
connection,
"version",
prefix+"version",
&migrate.MigratorOptions{
DisableTx: false,
},
@ -197,12 +202,13 @@ func SetupMigrator(prefix string, connection *pgx.Conn, migrations fs.FS) (mig *
log.Error().Err(err).Msg("Error while creating the migrator")
return
}
mig.OnStart = logmigrations
mig.Data["prefix"] = prefix
err = mig.LoadMigrations(migrations)
if err != nil {
log.Error().Err(err).Msg("Error while loading migrations")
return
}
mig.OnStart = logmigrations
mig.Data["prefix"] = prefix
log.Trace().Interface("migrations", mig.Migrations).Interface("data", mig.Data).Err(err).Send()
return
}

Datei anzeigen

@ -23,10 +23,14 @@ func LogMiddleware(c *gin.Context) {
var entry *zerolog.Event
interrupt := recover()
if interrupt != nil {
err := interrupt.(error)
entry = log.Error().Int("statuscode", 500)
if err, ok := interrupt.(error); ok {
entry.Err(err).Stack()
} else {
entry.Interface("recover", interrupt)
}
c.Header("requestid", id.String())
c.AbortWithStatus(http.StatusInternalServerError)
entry = log.Error().Err(err).Int("statuscode", 500)
entry.Stack()
} else {
statuscode := c.Writer.Status()
@ -40,7 +44,7 @@ func LogMiddleware(c *gin.Context) {
}
entry.Int("statuscode", statuscode)
}
entry.Bytes("xid", id.Bytes()).Msg("Request")
entry.Str("xid", id.String()).Msg("Request")
}()
c.Next()
}