Created
April 20, 2019 09:27
-
-
Save oliverpauffley/45f72dc04e63344677a060aa746da0b1 to your computer and use it in GitHub Desktop.
Handlers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"net/http" | |
) | |
type PlayerServer struct { | |
store PlayerStore | |
router *http.ServeMux | |
} | |
type PlayerStore interface { | |
GetPlayerScore(name string) int | |
RecordWin(name string) | |
} | |
func NewPlayerServer(store PlayerStore) *PlayerServer { | |
p := &PlayerServer{ | |
store, | |
http.NewServeMux(), | |
} | |
p.router.Handle("/league", http.HandlerFunc(p.leagueHandler)) | |
p.router.Handle("/players/", http.HandlerFunc(p.playersHandler)) | |
return p | |
} | |
func (p *PlayerServer) ServeHTTP(w http.ResponseWriter, r *http.Request) { | |
p.router.ServeHTTP(w, r) | |
} | |
// I'm not really sure on the last line. Is p.router.ServeHTTP running to a different function than my ServeHTTP? | |
// Get Playerscore and Record win are defined but doesn't matter for my question. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment