Skip to content

Commit 5f46802

Browse files
easyCZroboquat
authored andcommitted
[iam] Setup chi mux for routing
1 parent 5c6a297 commit 5f46802

File tree

4 files changed

+39
-1
lines changed

4 files changed

+39
-1
lines changed

components/iam/go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ go 1.19
44

55
require (
66
github.com/gitpod-io/gitpod/common-go v0.0.0-00010101000000-000000000000
7+
github.com/go-chi/chi/v5 v5.0.8
78
github.com/sirupsen/logrus v1.8.1
89
github.com/spf13/cobra v1.4.0
910
)

components/iam/go.sum

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/iam/pkg/oidc/router.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
2+
// Licensed under the GNU Affero General Public License (AGPL).
3+
// See License.AGPL.txt in the project root for license information.
4+
5+
package oidc
6+
7+
import (
8+
"github.com/go-chi/chi/v5"
9+
"net/http"
10+
)
11+
12+
func Router() *chi.Mux {
13+
router := chi.NewMux()
14+
15+
router.HandleFunc("/start", func(writer http.ResponseWriter, request *http.Request) {
16+
writer.Write([]byte(`hello`))
17+
})
18+
19+
return router
20+
}

components/iam/pkg/server/server.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ package server
66

77
import (
88
"fmt"
9-
109
"github.com/gitpod-io/gitpod/common-go/baseserver"
1110
"github.com/gitpod-io/gitpod/iam/pkg/config"
11+
"github.com/gitpod-io/gitpod/iam/pkg/oidc"
12+
"github.com/go-chi/chi/v5"
1213
"github.com/sirupsen/logrus"
1314
)
1415

@@ -24,9 +25,23 @@ func Start(logger *logrus.Entry, version string, cfg *config.ServiceConfig) erro
2425
return fmt.Errorf("failed to initialize iam server: %w", err)
2526
}
2627

28+
err = register(srv)
29+
if err != nil {
30+
return fmt.Errorf("failed to register services to iam server")
31+
}
32+
2733
if listenErr := srv.ListenAndServe(); listenErr != nil {
2834
return fmt.Errorf("failed to serve iam server: %w", err)
2935
}
3036

3137
return nil
3238
}
39+
40+
func register(srv *baseserver.Server) error {
41+
router := chi.NewMux()
42+
router.Mount("/oidc", oidc.Router())
43+
44+
// All root requests are handled by our router
45+
srv.HTTPMux().Handle("/", router)
46+
return nil
47+
}

0 commit comments

Comments
 (0)