mirror of
https://github.com/pcvolkmer/idicon.git
synced 2025-07-02 03:42:54 +00:00
Extract configuration types
This commit is contained in:
23
idicon.go
23
idicon.go
@ -124,7 +124,7 @@ func drawImage(data []bool, blocks int, size int, c color.Color) *image.NRGBA {
|
||||
return img
|
||||
}
|
||||
|
||||
func RequestHandler(w http.ResponseWriter, r *http.Request) {
|
||||
func requestHandler(w http.ResponseWriter, r *http.Request) {
|
||||
id := mux.Vars(r)["id"]
|
||||
|
||||
size, err := strconv.Atoi(r.URL.Query().Get("s"))
|
||||
@ -143,7 +143,7 @@ func RequestHandler(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
for _, userConfig := range config.Users {
|
||||
if hashBytes(id) == hashBytes(userConfig.Id) {
|
||||
if hashBytes(id) == hashBytes(userConfig.ID) {
|
||||
id = userConfig.Alias
|
||||
if len(userConfig.ColorScheme) > 0 {
|
||||
colorScheme = userConfig.ColorScheme
|
||||
@ -170,23 +170,6 @@ func RequestHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
Defaults Defaults `toml:"defaults"`
|
||||
Users []UserConfig `toml:"users"`
|
||||
}
|
||||
|
||||
type Defaults struct {
|
||||
ColorScheme string `toml:"color-scheme"`
|
||||
Pattern string `toml:"pattern"`
|
||||
}
|
||||
|
||||
type UserConfig struct {
|
||||
Id string `toml:"id"`
|
||||
Alias string `toml:"alias"`
|
||||
ColorScheme string `toml:"color-scheme"`
|
||||
Pattern string `toml:"pattern"`
|
||||
}
|
||||
|
||||
var (
|
||||
config Config
|
||||
)
|
||||
@ -219,7 +202,7 @@ func main() {
|
||||
configure(*configFile)
|
||||
|
||||
router := mux.NewRouter()
|
||||
router.HandleFunc("/avatar/{id}", RequestHandler)
|
||||
router.HandleFunc("/avatar/{id}", requestHandler)
|
||||
log.Println("Starting ...")
|
||||
log.Fatal(http.ListenAndServe(":8000", router))
|
||||
}
|
||||
|
Reference in New Issue
Block a user