-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
45 lines (37 loc) · 763 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package main
import (
"fmt"
"log"
"net/http"
"strconv"
)
func sendResponse(w http.ResponseWriter, r *http.Request) {
keys, ok := r.URL.Query()["a"]
if !ok || len(keys[0]) < 1 {
log.Println("Url Param 'a' is missing")
return
}
a, err := strconv.Atoi(keys[0])
if err != nil {
return
}
keys, ok = r.URL.Query()["b"]
if !ok || len(keys[0]) < 1 {
log.Println("Url Param 'b' is missing")
return
}
b, err := strconv.Atoi(keys[0])
if err != nil {
log.Println("Bad number!")
return
}
fmt.Fprintf(w, "%d + %d = %d", a, b, sum(a,b))
}
func main() {
http.HandleFunc("/", sendResponse)
log.Fatal(http.ListenAndServe(":7000", nil))
}
func sum (a, b int) int {
t := b + a
return t
}