-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
57 lines (49 loc) · 1.54 KB
/
main.go
File metadata and controls
57 lines (49 loc) · 1.54 KB
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
50
51
52
53
54
55
56
57
package main
import (
"fmt"
"log"
"net/http"
"os"
"github.com/tidwall/gjson"
)
func loadConfig(filename string) (gjson.Result, error) {
data, err := os.ReadFile(filename)
if err != nil {
return gjson.Result{}, fmt.Errorf("unable to read config file: %v", err)
}
config := gjson.ParseBytes(data)
return config, nil
}
func main() {
config, err := loadConfig("Config.json")
if err != nil {
log.Fatalf("Error loading config: %v", err)
}
go downloadAndHashImages(config)
http.HandleFunc("/en", RateLimited(func(w http.ResponseWriter, r *http.Request) {
getHash(w, r, &state.EnImageHash)
}))
http.HandleFunc("/en_p", RateLimited(func(w http.ResponseWriter, r *http.Request) {
getHash(w, r, &state.EnPImageHash)
}))
http.HandleFunc("/es", RateLimited(func(w http.ResponseWriter, r *http.Request) {
getHash(w, r, &state.EsImageHash)
}))
http.HandleFunc("/es_p", RateLimited(func(w http.ResponseWriter, r *http.Request) {
getHash(w, r, &state.EsPImageHash)
}))
http.HandleFunc("/fr", RateLimited(func(w http.ResponseWriter, r *http.Request) {
getHash(w, r, &state.FrImageHash)
}))
http.HandleFunc("/po", RateLimited(func(w http.ResponseWriter, r *http.Request) {
getHash(w, r, &state.PoImageHash)
}))
http.HandleFunc("/it", RateLimited(func(w http.ResponseWriter, r *http.Request) {
getHash(w, r, &state.ItImageHash)
}))
http.HandleFunc("/de", RateLimited(func(w http.ResponseWriter, r *http.Request) {
getHash(w, r, &state.DeImageHash)
}))
log.Println("Starting server on :9191")
log.Fatal(http.ListenAndServe(":9191", nil))
}