@@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -21,6 +22,15 @@ func main() {
|
||||
mux.HandleFunc("/version", func(w http.ResponseWriter, r *http.Request) {
|
||||
json.NewEncoder(w).Encode(map[string]string{"version": version})
|
||||
})
|
||||
mux.HandleFunc("/sum", 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": sum(a, b)})
|
||||
})
|
||||
|
||||
http.ListenAndServe(":8080", mux)
|
||||
}
|
||||
|
||||
func sum(a, b int) int {
|
||||
return a + b
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user