Created
December 14, 2017 13:42
-
-
Save meskio/eb81c18f33e703c05d4f3693354a759d to your computer and use it in GitHub Desktop.
dummy katzenpost auth
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 ( | |
"encoding/json" | |
"log" | |
"net/http" | |
) | |
var keys = make(map[string]string) | |
func main() { | |
log.Println("Start dummy ath") | |
http.HandleFunc("/isvalid", isvalid) | |
http.HandleFunc("/exists", exists) | |
http.HandleFunc("/add", add) | |
http.HandleFunc("/remove", remove) | |
log.Fatal(http.ListenAndServe(":8080", nil)) | |
} | |
func isvalid(w http.ResponseWriter, r *http.Request) { | |
result := map[string]bool{"isvalid": false} | |
user := r.FormValue("user") | |
key := r.FormValue("key") | |
if keys[user] == key { | |
result["isvalid"] = true | |
} | |
resultBytes, err := json.Marshal(result) | |
if err != nil { | |
return | |
} | |
w.Write(resultBytes) | |
} | |
func exists(w http.ResponseWriter, r *http.Request) { | |
result := map[string]bool{"exists": false} | |
user := r.FormValue("user") | |
if keys[user] != "" { | |
result["exists"] = true | |
} | |
resultBytes, err := json.Marshal(result) | |
if err != nil { | |
return | |
} | |
w.Write(resultBytes) | |
} | |
func add(w http.ResponseWriter, r *http.Request) { | |
result := map[string]bool{"add": true} | |
user := r.FormValue("user") | |
key := r.FormValue("key") | |
keys[user] = key | |
resultBytes, err := json.Marshal(result) | |
if err != nil { | |
return | |
} | |
w.Write(resultBytes) | |
} | |
func remove(w http.ResponseWriter, r *http.Request) { | |
result := map[string]bool{"remove": true} | |
user := r.FormValue("user") | |
delete(keys, user) | |
resultBytes, err := json.Marshal(result) | |
if err != nil { | |
return | |
} | |
w.Write(resultBytes) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment