forked from RedHatInsights/back-office-proxy-mock
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinsights-services.go
38 lines (32 loc) · 945 Bytes
/
insights-services.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
package main
import (
"net/http"
"log"
"encoding/json"
"os"
"io/ioutil"
"github.com/gorilla/mux"
)
type User struct{
Id int `json:"id"`
Username string `json:"username"`
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
Email string `json:"email"`
IsActive bool `json:"is_active"`
Locale string `json:"locale"`
}
func usersForAccount(w http.ResponseWriter, req *http.Request) {
jsonFile, _ := os.Open("data/users.json")
defer jsonFile.Close()
byteValue, _ := ioutil.ReadAll(jsonFile)
users := []User{}
json.Unmarshal(byteValue, &users)
json.NewEncoder(w).Encode(users)
}
func main() {
router := mux.NewRouter()
router.HandleFunc("/insights-services/v1/accounts/{id}/users", usersForAccount)
log.Println("Listening on :8090")
log.Fatal(http.ListenAndServe(":8090", router))
}