-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnewrest.go
More file actions
49 lines (38 loc) · 907 Bytes
/
newrest.go
File metadata and controls
49 lines (38 loc) · 907 Bytes
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
46
47
48
49
package main
import (
"fmt"
"net/http"
"github.com/connect2naga/Training/pkg"
"github.com/gorilla/mux"
)
type APIHandler struct {
odd chan(int)
even chan(int)
}
func (a *APIHandler) SayHello(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
value := r.URL.Query()
w.Write([]byte(fmt.Sprintf("<h1>%s from %s</h1>",vars["name"], value["location"])))
}
func (a *APIHandler) Print(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
fmt.Printf("%s",vars["intValue"])
//val := 0
val, _ := strconv.Atoi(vars["intValue"])
fmt.Printf("CONV STRING:%v",val)
switch val %2 {
case 0:
a.even <- val
case 1:
a.odd <- val
default :
}
}
func main() {
a := pkg.APIHandler{}
r := mux.NewRouter()
r.HandleFunc("/hello/{name}", a.SayHello)
r.HandleFunc("/number/{intValue}", a.Print)
fmt.Printf("Server started at :8080....")
http.ListenAndServe(":8080", r)
}