-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
49 lines (36 loc) · 901 Bytes
/
main.go
File metadata and controls
49 lines (36 loc) · 901 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 (
"encoding/json"
"fmt"
"log"
"net/http"
"os"
"github.com/Bakarseck/api/internals/utils"
)
type Words struct {
Id int `json:"id"`
French string `json:"français"`
English string `json:"anglais"`
Chinois string `json:"chinois"`
}
var words []Words
func getUserHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(words)
}
func main() {
http.NewServeMux()
utils.LoadEnv(".env")
port := os.Getenv("PORT")
log.Print(os.Getenv("AUTHOR"))
file, err := os.Open("second.json")
if err != nil {
log.Println(err.Error())
return
}
defer file.Close()
json.NewDecoder(file).Decode(&words)
http.HandleFunc("/users", getUserHandler)
log.Printf("Serveur en cours d'exécution sur http://localhost:%v\n", port)
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%v", port), nil))
}