-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrouter.go
67 lines (54 loc) · 1.97 KB
/
router.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
/*
* Copyright (C) 2017 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package web
import (
"net/http"
"github.com/gorilla/mux"
)
// managementHandler handles requests for web UI when AP is up
func managementRouter(ssidsMap map[string]string) *mux.Router {
router := mux.NewRouter()
ssids := make([]string, 0, len(ssidsMap))
for k := range ssidsMap {
ssids = append(ssids, k)
}
// only start in AP interface: 10.0.60.1
address = "10.0.60.1:8080"
// Pages routes
router.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
managementHandler(w, r, ssids)
})
// router.HandleFunc("/connect", ConnectHandler).Methods("POST")
// router.HandleFunc("/hashit", HashItHandler).Methods("POST")
// router.HandleFunc("/refresh", RefreshHandler).Methods("GET")
// Resources path
fs := http.StripPrefix("/static/", http.FileServer(http.Dir(resourcesPath)))
router.PathPrefix("/static/").Handler(fs)
return router
}
// operationalHandler handles request for web UI when connected to external WIFI
func operationalRouter() *mux.Router {
router := mux.NewRouter()
address = ":8080"
router.HandleFunc("/", operationalHandler).Methods("GET")
// router.HandleFunc("/disconnect", DisconnectHandler).Methods("GET")
// router.HandleFunc("/hashit", HashItHandler).Methods("POST")
// Resources path
fs := http.StripPrefix("/static/", http.FileServer(http.Dir(resourcesPath)))
router.PathPrefix("/static/").Handler(fs)
return router
}