DevOpsGOServer
/
main.go
38 строк · 910.0 Байт
1package main
2
3import (
4httptransport "github.com/go-kit/kit/transport/http"
5"log"
6"net/http"
7)
8
9func main() {
10svc := stringService{}
11
12uppercaseHandler := httptransport.NewServer(
13makeUppercaseEndpoint(svc),
14decodeUppercaseRequest,
15encodeResponse,
16)
17
18countHandler := httptransport.NewServer(
19makeCountEndpoint(svc),
20decodeCountRequest,
21encodeResponse,
22)
23countHandler.Name = "count"
24countHandler.Methods = []string{"GET"}
25countHandler.Path = "/count"
26countHandler.AllowedMethods = []string{"GET"}
27countHandler.Handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {if r.Method != "GET" {
28w.WriteHeader(http.StatusMethodNotAllowed)
29return
30}
31countHandler.ServeHTTP(w, r)
32
33
34http.Handle("/", http.FileServer(http.Dir("./static")))
35http.Handle("/uppercase", uppercaseHandler)
36http.Handle("/count", countHandler)
37log.Fatal(http.ListenAndServe(":9090", nil))
38}
39