add sub function
This commit is contained in:
@@ -27,6 +27,11 @@ func main() {
|
||||
b, _ := strconv.Atoi(r.URL.Query().Get("b"))
|
||||
json.NewEncoder(w).Encode(map[string]int{"result": sum(a, b)})
|
||||
})
|
||||
mux.HandleFunc("/sub", func(w http.ResponseWriter, r *http.Request) {
|
||||
a, _ := strconv.Atoi(r.URL.Query().Get("a"))
|
||||
b, _ := strconv.Atoi(r.URL.Query().Get("b"))
|
||||
json.NewEncoder(w).Encode(map[string]int{"result": sub(a, b)})
|
||||
})
|
||||
|
||||
http.ListenAndServe(":8080", mux)
|
||||
}
|
||||
@@ -34,3 +39,7 @@ func main() {
|
||||
func sum(a, b int) int {
|
||||
return a + b
|
||||
}
|
||||
|
||||
func sub(a, b int) int {
|
||||
return a - b
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user