forked from gnolang/gno
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
60 lines (51 loc) · 1.85 KB
/
main.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
package main
import (
"flag"
"fmt"
"net/http"
"os"
"time"
// for static files
"github.com/gnolang/gno/gno.land/pkg/gnoweb"
"github.com/gnolang/gno/gno.land/pkg/log"
"go.uber.org/zap/zapcore"
// for error types
// "github.com/gnolang/gno/tm2/pkg/sdk" // for baseapp (info, status)
)
func main() {
err := runMain(os.Args[1:])
if err != nil {
_, _ = fmt.Fprintf(os.Stderr, "%+v\n", err)
os.Exit(1)
}
}
func runMain(args []string) error {
var (
fs = flag.NewFlagSet("gnoweb", flag.ContinueOnError)
cfg = gnoweb.NewDefaultConfig()
bindAddress string
)
fs.StringVar(&cfg.RemoteAddr, "remote", cfg.RemoteAddr, "remote gnoland node address")
fs.StringVar(&cfg.CaptchaSite, "captcha-site", cfg.CaptchaSite, "recaptcha site key (if empty, captcha are disabled)")
fs.StringVar(&cfg.FaucetURL, "faucet-url", cfg.FaucetURL, "faucet server URL")
fs.StringVar(&cfg.ViewsDir, "views-dir", cfg.ViewsDir, "views directory location") // XXX: replace with goembed
fs.StringVar(&cfg.HelpChainID, "help-chainid", cfg.HelpChainID, "help page's chainid")
fs.StringVar(&cfg.HelpRemote, "help-remote", cfg.HelpRemote, "help page's remote addr")
fs.BoolVar(&cfg.WithAnalytics, "with-analytics", cfg.WithAnalytics, "enable privacy-first analytics")
fs.StringVar(&bindAddress, "bind", "127.0.0.1:8888", "server listening address")
if err := fs.Parse(args); err != nil {
return err
}
zapLogger := log.NewZapConsoleLogger(os.Stdout, zapcore.DebugLevel)
logger := log.ZapLoggerToSlog(zapLogger)
logger.Info("Running", "listener", "http://"+bindAddress)
server := &http.Server{
Addr: bindAddress,
ReadHeaderTimeout: 60 * time.Second,
Handler: gnoweb.MakeApp(logger, cfg).Router,
}
if err := server.ListenAndServe(); err != nil {
logger.Error("HTTP server stopped", " error:", err)
}
return zapLogger.Sync()
}