Changed ExtendedApp to use ServeMux directly

More work on portfolio stuff
Added technologies to portfolio projects
This commit is contained in:
Caleb Gardner
2024-07-27 02:38:31 -05:00
parent f59a4207c4
commit cb53b7b831
7 changed files with 48 additions and 27 deletions
+2 -3
View File
@@ -15,10 +15,9 @@ type CrashFilterApp interface {
AddCrash(IndividualCrash) bool
}
// Allows an app more flexibility by directly interfacing with the backend's mux
type ExtendedApp interface {
// Extension is called for any calls to /{appID}/
// Alternatively, use Backend.HandleFunc for more customizability
Extension(http.ResponseWriter, *http.Request)
Extension(*http.ServeMux)
}
type simpleApp struct {
+3 -1
View File
@@ -44,7 +44,7 @@ func NewBackend(keyTable Table[ApiKey], apps ...App) (*Backend, error) {
}
b.apps[apps[i].AppID()] = apps[i]
if ext, is := apps[i].(ExtendedApp); is {
b.m.HandleFunc("/"+apps[i].AppID()+"/", ext.Extension)
ext.Extension(b.m)
}
if !hasLog && apps[i].CountTable() != nil {
hasLog = true
@@ -124,10 +124,12 @@ func (b *Backend) AddUserAuth(userTable Table[User], privKey, pubKey []byte) {
b.m.HandleFunc("POST /user/login", b.login)
}
// Add values to the Backend's underlying ServeMux
func (b *Backend) HandleFunc(pattern string, h http.HandlerFunc) {
b.m.HandleFunc(pattern, h)
}
// Try to get the App associated with the given ApiKey. Returns nil if not found.
func (b *Backend) GetApp(a *ApiKey) App {
return b.apps[a.AppID]
}