Create public static files to serve
parent
1a3ba7c5e9
commit
a255d391b5
|
|
@ -7,6 +7,7 @@ import (
|
||||||
|
|
||||||
var (
|
var (
|
||||||
Port string
|
Port string
|
||||||
|
Public string
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
@ -16,8 +17,10 @@ func init() {
|
||||||
func New() {
|
func New() {
|
||||||
as := args.NewArgSet()
|
as := args.NewArgSet()
|
||||||
as.Append(args.INT, "p", "port to listen on", 52222)
|
as.Append(args.INT, "p", "port to listen on", 52222)
|
||||||
|
as.Append(args.STRING, "d", "dir with public files", "./public")
|
||||||
if err := as.Parse(); err != nil {
|
if err := as.Parse(); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
Port = fmt.Sprintf(":%d", as.GetInt("p"))
|
Port = fmt.Sprintf(":%d", as.GetInt("p"))
|
||||||
|
Public = as.GetString("d")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Hi</h1>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
@ -1,9 +1,12 @@
|
||||||
package server
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
"local/cheqbooq/config"
|
||||||
"local/cheqbooq/server/account"
|
"local/cheqbooq/server/account"
|
||||||
"local/cheqbooq/server/balance"
|
"local/cheqbooq/server/balance"
|
||||||
"local/cheqbooq/server/transaction"
|
"local/cheqbooq/server/transaction"
|
||||||
|
"local/router"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -12,6 +15,7 @@ func (s *Server) Routes() error {
|
||||||
"api/v1/balance": s.balance1,
|
"api/v1/balance": s.balance1,
|
||||||
"api/v1/transaction": s.transaction1,
|
"api/v1/transaction": s.transaction1,
|
||||||
"api/v1/account": s.account1,
|
"api/v1/account": s.account1,
|
||||||
|
fmt.Sprintf("%s%s", router.Wildcard, router.Wildcard): s.public,
|
||||||
}
|
}
|
||||||
for path, handler := range routes {
|
for path, handler := range routes {
|
||||||
if err := s.Add(path, handler); err != nil {
|
if err := s.Add(path, handler); err != nil {
|
||||||
|
|
@ -51,3 +55,8 @@ func (s *Server) account1(w http.ResponseWriter, r *http.Request) {
|
||||||
http.NotFound(w, r)
|
http.NotFound(w, r)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Server) public(w http.ResponseWriter, r *http.Request) {
|
||||||
|
d := http.FileServer(http.Dir(config.Public))
|
||||||
|
d.ServeHTTP(w, r)
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue