-
Notifications
You must be signed in to change notification settings - Fork 21
/
setup.go
44 lines (36 loc) · 817 Bytes
/
setup.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
package api
import (
"github.com/evilsocket/pwngrid/crypto"
"github.com/evilsocket/pwngrid/mesh"
"github.com/go-chi/chi"
"net/http"
_ "github.com/jinzhu/gorm/dialects/mysql"
"github.com/evilsocket/islazy/log"
)
type API struct {
Router *chi.Mux
Keys *crypto.KeyPair
Peer *mesh.Peer
Mesh *mesh.Router
Client *Client
}
func Setup(keys *crypto.KeyPair, peer *mesh.Peer, router *mesh.Router) (err error, api *API) {
api = &API{
Router: chi.NewRouter(),
Keys: keys,
Peer: peer,
Mesh: router,
Client: NewClient(keys),
}
api.Router.Use(CORS)
if api.Keys == nil {
api.setupServerRoutes()
} else {
api.setupPeerRoutes()
}
return
}
func (api *API) Run(addr string) {
log.Info("pwngrid api starting on %s ...", addr)
log.Fatal("%v", http.ListenAndServe(addr, api.Router))
}