forked from sfreiberg/powerrest
-
Notifications
You must be signed in to change notification settings - Fork 1
/
powerrest.go
46 lines (37 loc) · 1.4 KB
/
powerrest.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
package main
import (
_ "github.com/go-sql-driver/mysql"
"github.com/gorilla/mux"
_ "github.com/lib/pq"
"database/sql"
"log"
"net/http"
)
var (
db *sql.DB
conf *Config
)
func main() {
var err error
conf, err = LoadConfig()
if err != nil {
log.Fatal(err)
}
db, err = sql.Open(conf.DbType, conf.DbConn)
if err != nil {
log.Fatal(err)
}
router := mux.NewRouter()
router.HandleFunc("/v1/domains", domainIndex).Methods("GET") // list domains
router.HandleFunc("/v1/domains", domainCreate).Methods("POST") // new domain
router.HandleFunc("/v1/domains/{id:[0-9]+}", domainShow).Methods("GET") // show domain
router.HandleFunc("/v1/domains/{id:[0-9]+}", domainUpdate).Methods("POST") // update domain
router.HandleFunc("/v1/domains/{id:[0-9]+}", domainDelete).Methods("DELETE") // delete domain
router.HandleFunc("/v1/records", recordIndex).Methods("GET") // list domains
router.HandleFunc("/v1/records", recordCreate).Methods("POST") // new domain
router.HandleFunc("/v1/records/{id:[0-9]+}", recordShow).Methods("GET") // show domain
router.HandleFunc("/v1/records/{id:[0-9]+}", recordUpdate).Methods("POST") // update domain
router.HandleFunc("/v1/records/{id:[0-9]+}", recordDelete).Methods("DELETE") // delete domain
log.Println("Listening on", conf.ListenAddr)
log.Fatal(http.ListenAndServe(conf.ListenAddr, router))
}