Commits vergleichen
17 Commits
Autor | SHA1 | Datum | |
---|---|---|---|
5717ec7a91 | |||
9ac6b96eee | |||
818560df17 | |||
4aa50328f2 | |||
b71fcb8fa2 | |||
f8a7689fea | |||
1d647c7d00 | |||
2326ceb32e | |||
8d9b870820 | |||
b5800f09c2 | |||
0f9fded567 | |||
1b64551582 | |||
bf60ad409c | |||
d744ff8205 | |||
4244e2728d | |||
7cf90595e6 | |||
ecdf2c5b77 |
6 geänderte Dateien mit 178 neuen und 86 gelöschten Zeilen
2
.gitignore
gevendort
Normale Datei
2
.gitignore
gevendort
Normale Datei
|
@ -0,0 +1,2 @@
|
|||
go.work
|
||||
go.work.sum
|
34
go.mod
34
go.mod
|
@ -6,37 +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.0.0 // indirect
|
||||
github.com/shopspring/decimal v1.3.1 // indirect
|
||||
github.com/spf13/cast v1.5.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/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.0.4
|
||||
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
|
||||
|
@ -46,13 +44,17 @@ require (
|
|||
github.com/mitchellh/reflectwalk v1.0.2 // indirect
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||
github.com/pelletier/go-toml/v2 v2.0.5 // indirect
|
||||
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
|
||||
golang.org/x/crypto v0.1.0 // indirect
|
||||
golang.org/x/net v0.1.0 // indirect
|
||||
golang.org/x/sys v0.1.0 // indirect
|
||||
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
|
||||
|
|
42
go.sum
42
go.sum
|
@ -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=
|
||||
|
@ -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.0.4 h1:r5O6y84qHX/z/HZV40JBdx2obsHz7/uRj5b+CcYEdeY=
|
||||
github.com/jackc/pgx/v5 v5.0.4/go.mod h1:U0ynklHtgg43fue9Ly30w3OCSTDPlXjig9ghrNGaguQ=
|
||||
github.com/jackc/puddle/v2 v2.0.0 h1:Kwk/AlLigcnZsDssc3Zun1dk1tAtQNPaBBxBHWn0Mjc=
|
||||
github.com/jackc/puddle/v2 v2.0.0/go.mod h1:itE7ZJY8xnoo0JqJEpSMprN0f+NQkMCuEV/N9j8h0oc=
|
||||
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,8 @@ 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=
|
||||
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||
|
@ -120,6 +123,7 @@ github.com/spf13/cast v1.5.0 h1:rj3WzYc11XZaIZMPKmwP96zkFEnnAmV8s6XbB2aY32w=
|
|||
github.com/spf13/cast v1.5.0/go.mod h1:SpXXQ5YoyJw6s3/6cMTQuxvgRl3PCJiyaX9p6b155UU=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
||||
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||
|
@ -127,21 +131,29 @@ 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=
|
||||
github.com/ugorji/go v1.2.7 h1:qYhyWUUd6WbiM+C6JZAUkIJt/1WrjzNHY9+KCIjVqTo=
|
||||
github.com/ugorji/go v1.2.7/go.mod h1:nF9osbDWLy6bDVv/Rtoh6QgnvNDpmCalQV5urGCCS6M=
|
||||
github.com/ugorji/go/codec v1.2.7 h1:YPXUKf7fYbp/y8xloBqZOw2qaVggbfwMlI8WM3wZUJ0=
|
||||
github.com/ugorji/go/codec v1.2.7/go.mod h1:WGN1fab3R1fzQlVQTkfxVtIBhWDRqOviHU95kRgeqEY=
|
||||
go.sebtobie.de/generic v1.0.1 h1:N7q6nu5y9+QowBUj49qQgcDxYOxMy+ZIzFhQntclCxQ=
|
||||
go.sebtobie.de/generic v1.0.1/go.mod h1:3AAmr4JfoP2PD7VzRJBAjn+ZiRgaLCYKSOf3wn0nNCM=
|
||||
go.uber.org/atomic v1.10.0 h1:9qC72Qh0+3MqyJbAn8YU5xVq1frD8bn3JtD2oXtafVQ=
|
||||
go.uber.org/atomic v1.10.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
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.1.0 h1:MDRAIl0xIo9Io2xV565hzXHw3zVseKrJKodhohM5CjU=
|
||||
golang.org/x/crypto v0.1.0/go.mod h1:RecgLatLF4+eUMCP1PoPZQb+cVrJcOPbHkTkbkB9sbw=
|
||||
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.1.0 h1:hZ/3BUoy5aId7sCpA/Tc5lt8DkFgdVS2onTpJsZ/fl0=
|
||||
golang.org/x/net v0.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco=
|
||||
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.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=
|
||||
|
@ -151,8 +163,8 @@ golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBc
|
|||
golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.1.0 h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U=
|
||||
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.2.0 h1:ljd4t30dBnAvMZaQCevtY0xLLD0A+bRZXbgLMLU1F/A=
|
||||
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
|
|
102
http.go
102
http.go
|
@ -12,6 +12,7 @@ import (
|
|||
"github.com/flosch/pongo2/v6"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/rs/zerolog/log"
|
||||
"go.sebtobie.de/generic"
|
||||
"go.sebtobie.de/httpserver/auth"
|
||||
"go.sebtobie.de/httpserver/constants"
|
||||
"go.sebtobie.de/httpserver/funcs"
|
||||
|
@ -52,18 +53,20 @@ type Server struct {
|
|||
authh auth.AuthenticationHandler
|
||||
middleware gin.HandlersChain
|
||||
advmiddleware map[string]middleware.Middleware
|
||||
alldomainsites []Site
|
||||
}
|
||||
|
||||
// CreateServer creates an server that can be run in a coroutine.
|
||||
func CreateServer() *Server {
|
||||
log.Info().Msg("Redirect logging output to phuslu/log")
|
||||
log.Info().Msg("Redirect logging output to zerolog")
|
||||
gin.DefaultErrorWriter = log.Logger.With().Str("source", "GIN").Logger()
|
||||
gin.DefaultWriter = log.Logger.With().Str("source", "GIN").Logger()
|
||||
log.Info().Msg("Creating HTTP-Server")
|
||||
var server = &Server{
|
||||
Conf: &Config{
|
||||
TLSconfig: &tls.Config{},
|
||||
Sites: map[string]SiteConfig{},
|
||||
TLSconfig: &tls.Config{},
|
||||
Sites: map[string]SiteConfig{},
|
||||
Middleware: map[string]middleware.Config{},
|
||||
},
|
||||
mrouter: map[string]*gin.Engine{},
|
||||
authh: &auth.AnonAccountHandler{},
|
||||
|
@ -72,6 +75,8 @@ func CreateServer() *Server {
|
|||
sites: map[string]Site{},
|
||||
middleware: gin.HandlersChain{},
|
||||
template: pongo2.NewSet("templates", &templates.EmptyLoader{}),
|
||||
advmiddleware: map[string]middleware.Middleware{},
|
||||
alldomainsites: []Site{},
|
||||
}
|
||||
server.http = &http.Server{
|
||||
ErrorLog: intlog.New(log.Logger, "", 0),
|
||||
|
@ -129,13 +134,13 @@ func (s *Server) StartServer() {
|
|||
log.Info().Msg("Starting server")
|
||||
s.http.TLSConfig = s.Conf.TLSconfig
|
||||
if s.Conf.Certfile != "" && s.Conf.Keyfile != "" {
|
||||
s.routines.Add(len(s.Conf.TLSAddr))
|
||||
for _, addr := range s.Conf.TLSAddr {
|
||||
s.routines.Add(1)
|
||||
go s.runPort(addr, true)
|
||||
}
|
||||
}
|
||||
s.routines.Add(len(s.Conf.Addr))
|
||||
for _, addr := range s.Conf.Addr {
|
||||
s.routines.Add(1)
|
||||
go s.runPort(addr, false)
|
||||
}
|
||||
s.routines.Wait()
|
||||
|
@ -153,9 +158,11 @@ func (s *Server) DomainRouter(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
r.Host = domain
|
||||
r.URL.Host = domain
|
||||
trch := log.Trace()
|
||||
for header, value := range map[string][]string(r.Header) {
|
||||
log.Trace().Strs(header, value).Msg("Headers")
|
||||
trch.Strs(header, value)
|
||||
}
|
||||
trch.Msg("Headers")
|
||||
if router, found := s.mrouter[domain]; found {
|
||||
router.NoMethod(gin.WrapH(s.NotFoundHandler))
|
||||
router.NoRoute(gin.WrapH(s.NotFoundHandler))
|
||||
|
@ -181,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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -201,6 +209,29 @@ func maptoarray(m map[string]Site) (a []any) {
|
|||
return
|
||||
}
|
||||
|
||||
func (s *Server) newrouter(domain string) *gin.Engine {
|
||||
log.Info().Msgf("Setting up router for %s", domain)
|
||||
router := gin.New()
|
||||
router.Use(func(c *gin.Context) {
|
||||
c.Set(constants.Domain, domain)
|
||||
c.Set(constants.Menus, s.menus)
|
||||
c.Set(constants.Accounts, s.authh.Account(c))
|
||||
})
|
||||
router.Use(s.middleware...)
|
||||
router.HTMLRender = templates.NewPongo2Renderer(s.template)
|
||||
s.mrouter[domain] = router
|
||||
for _, site := range s.alldomainsites {
|
||||
site.Init(router.Group("/"))
|
||||
}
|
||||
return router
|
||||
}
|
||||
|
||||
func unequal[T comparable](i T) func(t T) bool {
|
||||
return func(t T) bool {
|
||||
return t != i
|
||||
}
|
||||
}
|
||||
|
||||
// Setup sets the server up. It loads the sites and prepare the server for startup.
|
||||
// The Midleware and the site are setup in this Order:
|
||||
// 1. Middleware.Setup
|
||||
|
@ -208,7 +239,7 @@ func maptoarray(m map[string]Site) (a []any) {
|
|||
// 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
|
||||
|
@ -218,26 +249,37 @@ func (s *Server) Setup() {
|
|||
for cfg, m := range s.advmiddleware {
|
||||
m.Setup(s.Conf.Middleware[cfg])
|
||||
}
|
||||
var config SiteConfig
|
||||
var err error
|
||||
for cfg, site = range s.sites {
|
||||
config := s.Conf.Sites[cfg]
|
||||
if router, found = s.mrouter[config["domain"].(string)]; !found {
|
||||
log.Info().Msgf("Setting up router for %s", config["domain"].(string))
|
||||
router = gin.New()
|
||||
router.Use(func(c *gin.Context) {
|
||||
c.Set(constants.Domain, config["domain"])
|
||||
c.Set(constants.Menus, s.menus)
|
||||
c.Set(constants.Accounts, s.authh.Account(c))
|
||||
})
|
||||
router.Use(s.middleware...)
|
||||
router.HTMLRender = templates.NewPongo2Renderer(s.template)
|
||||
s.mrouter[config["domain"].(string)] = router
|
||||
config, found = s.Conf.Sites[cfg]
|
||||
var domain = "*"
|
||||
var path = "/"
|
||||
if found {
|
||||
if generic.Valid(config["domain"], unequal("")) {
|
||||
domain = config["domain"].(string)
|
||||
}
|
||||
if generic.Valid(config["path"], unequal("")) {
|
||||
path = config["path"].(string)
|
||||
}
|
||||
}
|
||||
log.Debug().Str("domain", domain).Str("path", path).Msgf("setting up site %s", cfg)
|
||||
if domain != "*" {
|
||||
if router, found = s.mrouter[domain]; !found {
|
||||
router = s.newrouter(domain)
|
||||
}
|
||||
group := router.Group(config["path"].(string))
|
||||
site.Init(group)
|
||||
} else {
|
||||
s.alldomainsites = append(s.alldomainsites, site)
|
||||
for _, router = range s.mrouter {
|
||||
site.Init(router.Group(path))
|
||||
}
|
||||
}
|
||||
group := router.Group(config["path"].(string))
|
||||
site.Init(group)
|
||||
}
|
||||
for _, m := range s.advmiddleware {
|
||||
if psm, ok := m.(middleware.PreSetupMiddleware); ok {
|
||||
if err := psm.PreSetup(maptoarray(s.sites)); err != nil {
|
||||
if err = psm.PreSetup(maptoarray(s.sites)); err != nil {
|
||||
log.Error().Err(err).Msg("Failed to setup midddleware (pre-site-setup). Stopping with the setup")
|
||||
return
|
||||
}
|
||||
|
@ -259,12 +301,18 @@ func (s *Server) Setup() {
|
|||
}
|
||||
}
|
||||
if cs, ok := site.(ConfigSite); ok {
|
||||
cs.Setup(config)
|
||||
if err = cs.Setup(config); err != nil {
|
||||
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 {
|
||||
if err := psm.PostSetup(maptoarray(s.sites)); err != nil {
|
||||
if err = psm.PostSetup(maptoarray(s.sites)); err != nil {
|
||||
log.Error().Err(err).Msg("Failed to setup midddleware (post-site-setup). Stopping with the setup")
|
||||
return
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package db
|
|||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"sync"
|
||||
|
@ -13,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
|
||||
|
@ -25,6 +28,17 @@ var _ ConnGet = NewMiddleware().GetConn
|
|||
var _ middleware.Middleware = &Middleware{}
|
||||
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 {
|
||||
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. ")
|
||||
}
|
||||
|
||||
// Middleware return a handler that sets the db into the context of every request.
|
||||
// uri is an url in the form dbtype:connectargs
|
||||
type Middleware struct {
|
||||
|
@ -49,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 {
|
||||
|
@ -92,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
|
||||
|
@ -132,23 +146,26 @@ func (m *Middleware) PostSetup(sites []any) (err error) {
|
|||
db *pgxpool.Pool
|
||||
)
|
||||
for _, s := range sites {
|
||||
site, ok := s.(MigrationSite)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
db, ok = m.databases[site.Database()]
|
||||
if !ok {
|
||||
return fmt.Errorf("Failed to get the database. The Databasepool %s does not exist", site.Database())
|
||||
}
|
||||
conn, err = db.Acquire(context.TODO())
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer conn.Release()
|
||||
mig, err = site.Migrations(conn.Conn())
|
||||
err = mig.Migrate(context.TODO())
|
||||
if err != nil {
|
||||
return
|
||||
|
||||
if site, ok := s.(MigrationSite); ok {
|
||||
|
||||
db, ok = m.databases[site.Database()]
|
||||
if !ok {
|
||||
return fmt.Errorf("Failed to get the database. The Databasepool %s does not exist", site.Database())
|
||||
}
|
||||
conn, err = db.Acquire(context.TODO())
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer conn.Release()
|
||||
mig, err = site.Migrations(conn.Conn())
|
||||
err = mig.Migrate(context.TODO())
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if poolsite, ok := s.(PoolSite); ok {
|
||||
poolsite.Pool(m.databases[site.Database()])
|
||||
}
|
||||
}
|
||||
}
|
||||
return
|
||||
|
@ -165,12 +182,18 @@ type MigrationSite interface {
|
|||
Migrations(*pgx.Conn) (*migrate.Migrator, error)
|
||||
}
|
||||
|
||||
// PoolSite is an interface for site that need access to the pool outside of requests
|
||||
type PoolSite interface {
|
||||
MigrationSite
|
||||
Pool(*pgxpool.Pool)
|
||||
}
|
||||
|
||||
// SetupMigrator sets up the migrator to migrate the database.
|
||||
func SetupMigrator(prefix string, connection *pgx.Conn, migrations fs.FS) (mig *migrate.Migrator, err error) {
|
||||
mig, err = migrate.NewMigratorEx(
|
||||
context.TODO(),
|
||||
connection,
|
||||
"version",
|
||||
prefix+"version",
|
||||
&migrate.MigratorOptions{
|
||||
DisableTx: false,
|
||||
},
|
||||
|
@ -179,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
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
|
Laden …
Tabelle hinzufügen
In neuem Issue referenzieren