Skip to content

Custom ServeMux usage #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion firebase.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package firebase // import "github.com/captaincodeman/go-firebase"
package firebase

import (
"fmt"
Expand Down
12 changes: 12 additions & 0 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,17 @@ type (
generateURI string
verifyURI string
allowedOrigins []string
serveMux *http.ServeMux
}
)

// ServerServeMux Uses the existing ServeMux
func ServerServeMux(m *http.ServeMux) func(*Server) {
return func(s *Server) {
s.serveMux = m
}
}

// ServerGenerateURI Sets URI for the token generation
func ServerGenerateURI(uri string) func(*Server) {
return func(s *Server) {
Expand Down Expand Up @@ -66,6 +74,9 @@ func (a *Auth) Server(claimsFn CreateClaimsFunc, options ...func(*Server)) http.

// endpoints to issue and verify tokens
m := http.NewServeMux()
if s.serveMux != nil {
m = s.serveMux
}

m.HandleFunc(s.generateURI, s.generateHandler)
m.HandleFunc(s.verifyURI, s.verifyHandler)
Expand Down Expand Up @@ -137,3 +148,4 @@ func (s *Server) verifyHandler(w http.ResponseWriter, r *http.Request) {
enc := json.NewEncoder(w)
enc.Encode(token.Claims())
}