Create public static files to serve
parent
1a3ba7c5e9
commit
a255d391b5
|
|
@ -6,7 +6,8 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
Port string
|
||||
Port string
|
||||
Public string
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
|
@ -16,8 +17,10 @@ func init() {
|
|||
func New() {
|
||||
as := args.NewArgSet()
|
||||
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 {
|
||||
panic(err)
|
||||
}
|
||||
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
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"local/cheqbooq/config"
|
||||
"local/cheqbooq/server/account"
|
||||
"local/cheqbooq/server/balance"
|
||||
"local/cheqbooq/server/transaction"
|
||||
"local/router"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
|
|
@ -12,6 +15,7 @@ func (s *Server) Routes() error {
|
|||
"api/v1/balance": s.balance1,
|
||||
"api/v1/transaction": s.transaction1,
|
||||
"api/v1/account": s.account1,
|
||||
fmt.Sprintf("%s%s", router.Wildcard, router.Wildcard): s.public,
|
||||
}
|
||||
for path, handler := range routes {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
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