diff options
author | Emile <git@emile.space> | 2025-02-19 19:53:25 +0100 |
---|---|---|
committer | Emile <git@emile.space> | 2025-02-19 19:53:25 +0100 |
commit | ae39f02812bcfe903e956220c890bfb7b9bb9ff4 (patch) | |
tree | dff7028627665a7d2cb7cd64533ac74ec8919379 /nix/templates/goapp/frontend/src/util.go | |
parent | 07425c679f7399284c0fe3dcbee54f45b23d07a0 (diff) |
removed the backend, added the frontend with oidc support
So I've added oidc support which is nice, yet I have to test this with some https foo, so I'm pushing this.
Diffstat (limited to 'nix/templates/goapp/frontend/src/util.go')
-rw-r--r-- | nix/templates/goapp/frontend/src/util.go | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/nix/templates/goapp/frontend/src/util.go b/nix/templates/goapp/frontend/src/util.go new file mode 100644 index 0000000..89d28ba --- /dev/null +++ b/nix/templates/goapp/frontend/src/util.go @@ -0,0 +1,58 @@ +package main + +import ( + "fmt" + "net/url" + "path" + "strings" +) + +func isStringInSlice(s string, slice []string) bool { + for _, x := range slice { + if s == x { + return true + } + } + + return false +} + +func filterText(input string, filters []string) (output string) { + if len(filters) == 0 { + return input + } + + for _, filter := range filters { + input = strings.Replace(input, filter, strings.Repeat("*", len(filter)), -1) + } + + return input +} + +func filterSliceOfText(input []string, filters []string) (output []string) { + for _, item := range input { + output = append(output, filterText(item, filters)) + } + + return output +} + +func getURLs(rootURL string) (publicURL *url.URL, redirectURL *url.URL, err error) { + if publicURL, err = url.Parse(rootURL); err != nil { + return nil, nil, err + } + + if publicURL.Scheme != "http" && publicURL.Scheme != "https" { + return nil, nil, fmt.Errorf("scheme must be http or https but it is '%s'", publicURL.Scheme) + } + + if !strings.HasSuffix(publicURL.Path, "/") { + publicURL.Path += "/" + } + + redirectURL = &url.URL{} + *redirectURL = *publicURL + redirectURL.Path = path.Join(redirectURL.Path, "/oauth2/callback") + + return publicURL, redirectURL, nil +} |