-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
57 lines (48 loc) · 1.38 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
package main
import (
"btc/web"
"flag"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
"runtime"
)
var (
version = "main"
gitCommitHash = ""
)
func main() {
var addr string
flag.StringVar(&addr, "addr", "localhost:8000", "")
flag.Parse()
app := echo.New()
app.Use(middleware.Recover())
app.Use(middleware.CORS())
app.Use(middleware.RequestID())
app.Use(middleware.Logger())
app.HideBanner = true
app.RouteNotFound("/*", web.DefaultNotFound)
// info
app.Any("/", func(c echo.Context) error {
return c.JSON(200, struct {
Code int `json:"code"`
Version string `json:"version"`
GoVersion string `json:"go-version"`
GitHash string `json:"git-commit-hash"`
}{
Code: 200,
Version: version,
GoVersion: runtime.Version(),
GitHash: gitCommitHash,
})
})
// addresses
app.Match([]string{"GET", "POST"}, "/address/new", web.NewAddress)
app.Match([]string{"GET", "POST"}, "/address/parse", web.ParseAddress)
app.Match([]string{"GET", "POST"}, "/address/new-multi-sig", web.NewMultiSigAddress)
// transactions
app.Match([]string{"GET", "POST"}, "/transaction/decode", web.DecodeTransaction)
app.POST("/transaction/create", web.CreateRawTransaction)
app.POST("/transaction/sign", web.SignTransaction)
app.POST("/transaction/create-and-sign", web.CreateAndSignTransaction)
app.Logger.Fatal(app.Start(addr))
}