-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweebsh.go
47 lines (36 loc) · 847 Bytes
/
weebsh.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
39
40
41
42
43
44
45
46
47
package main
import (
"fmt"
"net/http"
weebgo "github.com/Daniele122898/weeb.go/src"
"github.com/Daniele122898/weeb.go/src/data"
"github.com/gorilla/mux"
)
// WeebAuth authenticate with the weeb.sh API once
func WeebAuth() error {
err := weebgo.Authenticate(weebToken, data.WOLKE)
if err == nil {
return err
}
return err
}
// WeebshHandler Handle all incoming weeb.sh API requests
func WeebshHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Add("Content-Type", "application/json")
if !CheckIfAuthorized(w, r) {
return
}
vars := mux.Vars(r)
ri, err := weebgo.GetRandomImage(vars["type"], nil, data.ANY, data.FALSE, false)
if err != nil {
fmt.Println(err)
return
}
url := ri.Url
result := `
{
"url": "` + url + `"
}
`
w.Write([]byte(result))
}