-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
50 lines (42 loc) · 1.1 KB
/
main.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
package main
import (
"github.com/gorilla/mux"
"github.com/jinzhu/gorm"
"math/rand"
"net/http"
"time"
_ "github.com/jinzhu/gorm/dialects/sqlite"
)
var (
db *gorm.DB
)
func init() {
var err error
db, err = gorm.Open("sqlite3", "emailer.db")
if err != nil {
panic(err)
}
db.AutoMigrate(&User{})
InitConfig()
}
func main() {
r := mux.NewRouter()
r.HandleFunc("/request", RequestHandler).Methods("POST")
r.HandleFunc("/confirm/{id}", ConfirmHandler).Methods("GET")
r.HandleFunc("/check", CheckHandler).Methods("GET")
r.HandleFunc("/resend", ResendHandler).Methods("GET")
r.HandleFunc("/unsubscribe", UnsubscribeHandler).Methods("GET")
r.HandleFunc("/send", SendHandler).Methods("POST")
r.HandleFunc("/metrics", MetricsHandler)
http.ListenAndServe(":8000", r)
}
var characterRunes = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
// RandomString generates a random string of n length
func RandomString(n int) string {
b := make([]rune, n)
rand.Seed(time.Now().UnixNano())
for i := range b {
b[i] = characterRunes[rand.Intn(len(characterRunes))]
}
return string(b)
}