-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.go
34 lines (26 loc) · 697 Bytes
/
app.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
package main
import (
"log"
"net/http"
dapr "github.com/dapr/go-sdk/client"
"github.com/gorilla/mux"
)
type App struct {
Router *mux.Router
daprClient dapr.Client
}
func (a *App) Initialize(client dapr.Client) {
a.daprClient = client
a.Router = mux.NewRouter()
a.Router.HandleFunc("/", a.Hello).Methods("GET")
a.Router.HandleFunc("/inventory", a.GetInventory).Methods("GET")
}
func (a *App) Hello(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("Hello world! It's me"))
}
func (a *App) GetInventory(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("Inventory in stock"))
}
func (a *App) Run(addr string) {
log.Fatal(http.ListenAndServe(addr, a.Router))
}