-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.go
90 lines (71 loc) · 2.54 KB
/
util.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package main
import (
"net/http"
"strconv"
"github.com/go-chi/chi"
)
func cors(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.Header().Set("Access-Control-Allow-Origin", "http://localhost:3000")
w.Header().Set("Access-Control-Allow-Methods", "GET,PUT,POST,DELETE,OPTIONS")
w.Header().Set("Access-Control-Allow-Headers", "Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With")
w.Header().Set("Access-Control-Allow-Credentials", "true")
if (*r).Method == "OPTIONS" {
return
}
next.ServeHTTP(w, r)
})
}
func authentication(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
return
// logger := middleware.GetLogger(r)
// DEBUG
// ctx := context.WithValue(r.Context(), middleware.USERID, "d736b408-aa60-43a3-8daa-d6c21a23c417")
// next.ServeHTTP(w, r.WithContext(ctx))
// return
// DEBUG
// var sessionToken string
// if token := r.Header.Get(sessionTokenHeader); token != "" {
// sessionToken = token
// } else if c, err := r.Cookie("session_token"); err == nil {
// fmt.Println(c)
// sessionToken = c.Value
// }
// if sessionToken == "" {
// w.WriteHeader(http.StatusUnauthorized)
// return
// }
// response, err := redis.String(redisHandle.Do(redis.GetKey, sessionToken))
// if err != nil {
// logger.Error(err)
// w.WriteHeader(http.StatusInternalServerError)
// return
// }
// if response == "" {
// w.WriteHeader(http.StatusUnauthorized)
// return
// }
// next.ServeHTTP(w, r.WithContext(context.WithValue(r.Context(), middleware.USERID, response)))
})
}
// var sendGridClient = sendgrid.NewSendClient(flag.SendGridKey())
func getFromURL(r *http.Request, key string) string {
return chi.URLParam(r, key)
}
func URLQueryInt(r *http.Request, key string) int64 {
num, _ := strconv.ParseInt(r.URL.Query().Get(key), 10, 64)
return num
}
// SendEmail -
// func SendEmail(targetEmail string, url string) error {
// from := mail.NewEmail("Akari Trading Test", "esadakar@gmail.com")
// subject := "Welcome to Akari Trading - Verify Your Account"
// to := mail.NewEmail("AkariTrading Developer", targetEmail)
// plainTextContent := "Welcome to Akari Trading. :happypepe:"
// htmlContent := fmt.Sprintf("<a href='%v'> Verify your email. </a>", url)
// message := mail.NewSingleEmail(from, subject, to, plainTextContent, htmlContent)
// _, err := sendGridClient.Send(message)
// return err
// }