Use go-chi v5

This commit is contained in:
wpetit 2022-08-10 11:11:22 +02:00
parent d786d3a26f
commit 50041cbc39
8 changed files with 20 additions and 20 deletions

View File

@ -67,6 +67,9 @@ func getServiceContainer(ctx context.Context, conf *config.Config) (*service.Con
conf.HTTP.TemplateDir, conf.HTTP.TemplateDir,
)) ))
// Create and expose config service provider
ctn.Provide(config.ServiceName, config.ServiceProvider(conf))
defaultHTTPTransport, ok := http.DefaultTransport.(*http.Transport) defaultHTTPTransport, ok := http.DefaultTransport.(*http.Transport)
if ok { if ok {
if defaultHTTPTransport.TLSClientConfig == nil { if defaultHTTPTransport.TLSClientConfig == nil {
@ -81,9 +84,6 @@ func getServiceContainer(ctx context.Context, conf *config.Config) (*service.Con
) )
} }
// Create and expose config service provider
ctn.Provide(config.ServiceName, config.ServiceProvider(conf))
provider, err := oidc.NewProvider(ctx, conf.OIDC.IssuerURL) provider, err := oidc.NewProvider(ctx, conf.OIDC.IssuerURL)
if err != nil { if err != nil {
return nil, errors.Wrap(err, "could not create oidc provider") return nil, errors.Wrap(err, "could not create oidc provider")

View File

@ -2,21 +2,19 @@ package main
import ( import (
"context" "context"
"flag"
"fmt"
"log"
"net/http" "net/http"
"os"
"forge.cadoles.com/wpetit/goweb-oidc/internal/config" "forge.cadoles.com/wpetit/goweb-oidc/internal/config"
"forge.cadoles.com/wpetit/goweb-oidc/internal/route" "forge.cadoles.com/wpetit/goweb-oidc/internal/route"
"github.com/go-chi/chi" "github.com/go-chi/chi/v5"
"github.com/go-chi/chi/middleware" "github.com/go-chi/chi/v5/middleware"
"gitlab.com/wpetit/goweb/middleware/container" "gitlab.com/wpetit/goweb/middleware/container"
"flag"
"fmt"
"log"
"os"
"github.com/pkg/errors" "github.com/pkg/errors"
"gitlab.com/wpetit/goweb/logger" "gitlab.com/wpetit/goweb/logger"
) )
@ -89,7 +87,6 @@ func main() {
} else { } else {
conf = config.NewDefault() conf = config.NewDefault()
} }
} }
// Dump configuration if asked // Dump configuration if asked
@ -140,6 +137,7 @@ func main() {
r := chi.NewRouter() r := chi.NewRouter()
// Define base middlewares // Define base middlewares
r.Use(middleware.CleanPath)
r.Use(middleware.Logger) r.Use(middleware.Logger)
r.Use(middleware.Recoverer) r.Use(middleware.Recoverer)

View File

@ -3,7 +3,7 @@
<div class="column is-4-tablet is-8-mobile"> <div class="column is-4-tablet is-8-mobile">
<div class="columns is-mobile is-gapless"> <div class="columns is-mobile is-gapless">
<div class="column is-narrow"> <div class="column is-narrow">
<h1 class="is-size-3 title"><a href="{{ .BaseURL }}" rel="Homepage" class="has-text-black">OIDC Test App</a></h1> <h1 class="is-size-3 title"><a href="{{ .BaseURL }}" rel="Homepage" class="has-text-black">OIDC Tester</a></h1>
</div> </div>
</div> </div>
</div> </div>

View File

@ -1,4 +1,4 @@
{{define "title"}}Home | OIDC Test App{{end}} {{define "title"}}Home | OIDC Tester{{end}}
{{define "body"}} {{define "body"}}
<section class="home is-fullheight section"> <section class="home is-fullheight section">
<div class="container"> <div class="container">

View File

@ -1,4 +1,4 @@
{{define "title"}}Profile | OIDC Test App{{end}} {{define "title"}}Profile | OIDC Tester{{end}}
{{define "body"}} {{define "body"}}
<section class="home is-fullheight section"> <section class="home is-fullheight section">
<div class="container"> <div class="container">

3
go.mod
View File

@ -6,7 +6,8 @@ require (
github.com/caarlos0/env/v6 v6.2.2 github.com/caarlos0/env/v6 v6.2.2
github.com/coreos/go-oidc v2.2.1+incompatible github.com/coreos/go-oidc v2.2.1+incompatible
github.com/dchest/uniuri v0.0.0-20200228104902-7aecb25e1fe5 github.com/dchest/uniuri v0.0.0-20200228104902-7aecb25e1fe5
github.com/go-chi/chi v4.1.0+incompatible github.com/go-chi/chi v4.1.2+incompatible // indirect
github.com/go-chi/chi/v5 v5.0.7
github.com/google/go-cmp v0.4.0 // indirect github.com/google/go-cmp v0.4.0 // indirect
github.com/gorilla/sessions v1.2.0 github.com/gorilla/sessions v1.2.0
github.com/pkg/errors v0.9.1 github.com/pkg/errors v0.9.1

6
go.sum
View File

@ -52,8 +52,10 @@ github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7
github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys= github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
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-chi/chi v4.1.0+incompatible h1:ETj3cggsVIY2Xao5ExCu6YhEh5MD6JTfcBzS37R260w= github.com/go-chi/chi v4.1.2+incompatible h1:fGFk2Gmi/YKXk0OmGfBh0WgmN3XB8lVnEyNz34tQRec=
github.com/go-chi/chi v4.1.0+incompatible/go.mod h1:eB3wogJHnLi3x/kFX2A+IbTBlXxmMeXJVKy9tTv1XzQ= github.com/go-chi/chi v4.1.2+incompatible/go.mod h1:eB3wogJHnLi3x/kFX2A+IbTBlXxmMeXJVKy9tTv1XzQ=
github.com/go-chi/chi/v5 v5.0.7 h1:rDTPXLDHGATaeHvVlLcR4Qe0zftYethFucbjVQ1PxU8=
github.com/go-chi/chi/v5 v5.0.7/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8=
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
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/go.mod h1:1AnU7NaIRDWWzGEKwgtJRd2xk99HeFyHw3yid4rvQIY= github.com/go-playground/universal-translator v0.16.0/go.mod h1:1AnU7NaIRDWWzGEKwgtJRd2xk99HeFyHw3yid4rvQIY=

View File

@ -4,12 +4,11 @@ import (
oidc "forge.cadoles.com/wpetit/goweb-oidc" oidc "forge.cadoles.com/wpetit/goweb-oidc"
"forge.cadoles.com/wpetit/goweb-oidc/internal/config" "forge.cadoles.com/wpetit/goweb-oidc/internal/config"
"github.com/go-chi/chi" chi "github.com/go-chi/chi/v5"
"gitlab.com/wpetit/goweb/static" "gitlab.com/wpetit/goweb/static"
) )
func Mount(r *chi.Mux, config *config.Config) error { func Mount(r *chi.Mux, config *config.Config) error {
r.With(oidc.HandleCallback).Get("/oauth2/callback", handleLoginCallback) r.With(oidc.HandleCallback).Get("/oauth2/callback", handleLoginCallback)
r.Get("/", serveHomePage) r.Get("/", serveHomePage)
r.Get("/logout", handleLogout) r.Get("/logout", handleLogout)