-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.go
39 lines (34 loc) · 1.12 KB
/
server.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
package main
import (
"os"
"log/syslog"
"net/http"
"github.com/calaniz/alanisoft/handlers"
"github.com/calaniz/alanisoft/handlers/util"
"github.com/gorilla/mux"
)
import logging "github.com/gorilla/handlers"
func NewRouter(logger *syslog.Writer) *mux.Router {
r := mux.NewRouter()
r.HandleFunc("/{name:[a-zA-Z0-9@/\\-_\\.]+.(js|css|html|json|png|svg|tff|woff|eot)$}", func(w http.ResponseWriter, r *http.Request) {
gopath := util.GetConfigKey("GOPATH", "/gopath")
if _, err := os.Stat(gopath + "/src/app/public" + r.URL.Path); err == nil {
http.ServeFile(w, r, gopath + "/src/app/public"+r.URL.Path)
} else {
http.ServeFile(w, r, gopath + "/src/github.com/calaniz/alanisoft/public"+r.URL.Path)
}
})
return r
}
func main() {
if logger, err := syslog.New(syslog.LOG_NOTICE|syslog.LOG_LOCAL1, "alanisoft-routing"); err != nil {
logger.Err(err.Error())
} else {
r := NewRouter(logger)
r.Handle("/", handlers.AppHandler(handlers.GetMain)).Methods("GET")
http.Handle("/", logging.CombinedLoggingHandler(logger, r))
if err := http.ListenAndServe(":8080", nil); err != nil {
logger.Crit(err.Error())
}
}
}