-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
116 lines (96 loc) · 4.99 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package main
import (
"fmt"
"github.com/navcoin/navexplorer-api-go/v2/generated/dic"
"github.com/navcoin/navexplorer-api-go/v2/internal/config"
"github.com/navcoin/navexplorer-api-go/v2/internal/framework"
"github.com/navcoin/navexplorer-api-go/v2/internal/resource"
"github.com/gin-contrib/gzip"
"github.com/gin-gonic/gin"
log "github.com/sirupsen/logrus"
"net/http"
)
var container *dic.Container
func main() {
config.Init()
container, _ = dic.NewContainer()
if config.Get().Debug {
log.SetLevel(log.DebugLevel)
}
framework.SetReleaseMode(config.Get().Debug)
r := gin.New()
r.Use(gzip.Gzip(gzip.DefaultCompression))
r.Use(gin.Logger())
r.Use(gin.Recovery())
r.Use(framework.Cors())
r.Use(framework.NetworkSelect)
r.Use(framework.Options)
r.Use(framework.ErrorHandler)
r.Use(framework.RR())
r.GET("/", func(c *gin.Context) {
c.String(http.StatusOK, "Welcome to NavExplorer API!")
})
authorized := r.Group("/auth", gin.BasicAuth(config.Account()))
addressResource := resource.NewAddressResource(container.GetAddressService(), container.GetCache())
r.GET("/address", addressResource.GetAddresses)
r.GET("/address/:hash", addressResource.GetAddress)
r.GET("/address/:hash/summary", addressResource.GetSummary)
r.GET("/address/:hash/history", addressResource.GetHistory)
r.GET("/address/:hash/validate", addressResource.ValidateAddress)
r.GET("/address/:hash/staking", addressResource.GetStakingChart)
r.GET("/address/:hash/assoc/staking", addressResource.GetAssociatedStakingAddresses)
r.GET("/balance", addressResource.GetBalancesForAddresses)
r.GET("/addressgroup", addressResource.GetAddressGroups)
r.GET("/addresses", addressResource.GetAddressGroupsTotal)
authorized.PUT("/address/:hash/meta", addressResource.PutAddressMeta)
distributionResource := resource.NewDistributionResource(container.GetAddressService(), container.GetBlockService())
r.GET("/distribution/supply", distributionResource.GetSupply)
r.GET("/distribution/wealth", distributionResource.GetWealth)
blockResource := resource.NewBlockResource(container.GetBlockService(), container.GetDaoService(), container.GetCache())
r.GET("/bestblock", blockResource.GetBestBlock)
r.GET("/blockcycle", blockResource.GetBestBlockCycle)
r.GET("/blockgroup", blockResource.GetBlockGroups)
r.GET("/block", blockResource.GetBlocks)
r.GET("/block/:hash", blockResource.GetBlock)
r.GET("/block/:hash/cycle", blockResource.GetBlockCycle)
r.GET("/block/:hash/raw", blockResource.GetRawBlock)
r.GET("/block/:hash/tx", blockResource.GetTransactionsByBlock)
r.GET("/tx", blockResource.GetTransactions)
r.GET("/tx/:hash", blockResource.GetTransactionByHash)
r.GET("/tx/:hash/raw", blockResource.GetRawTransactionByHash)
r.GET("/txcount", blockResource.CountTransactions)
stakingResource := resource.NewStakingResource(container.GetAddressService(), container.GetStakingService())
r.GET("/staking/blocks", stakingResource.GetBlocks)
r.GET("/staking/rewards", stakingResource.GetStakingRewardsForAddresses)
softForkResource := resource.NewSoftForkResource(container.GetSoftforkService(), container.GetSoftforkRepo())
r.GET("/softfork", softForkResource.GetSoftForks)
r.GET("/softfork/cycle", softForkResource.GetSoftForkCycle)
daoGroup := r.Group("/dao")
daoResource := resource.NewDaoResource(container.GetDaoService(), container.GetBlockService())
daoGroup.GET("/consensus/parameters", daoResource.GetConsensusParameters)
daoGroup.GET("/consensus/parameters/:id", daoResource.GetConsensusParameter)
daoGroup.GET("/consultation", daoResource.GetConsultations)
daoGroup.GET("/consultation/:hash", daoResource.GetConsultation)
daoGroup.GET("/answer/:hash", daoResource.GetAnswer)
daoGroup.GET("/consultation/:hash/:answer/votes", daoResource.GetAnswerVotes)
cfundGroup := daoGroup.Group("/cfund")
cfundGroup.GET("/stats", daoResource.GetCfundStats)
cfundGroup.GET("/proposal", daoResource.GetProposals)
cfundGroup.GET("/proposal/:hash", daoResource.GetProposal)
cfundGroup.GET("/proposal/:hash/votes", daoResource.GetProposalVotes)
cfundGroup.GET("/proposal/:hash/trend", daoResource.GetProposalTrend)
cfundGroup.GET("/proposal/:hash/payment-request", daoResource.GetPaymentRequestsForProposal)
cfundGroup.GET("/payment-request", daoResource.GetPaymentRequests)
cfundGroup.GET("/payment-request/:hash", daoResource.GetPaymentRequest)
cfundGroup.GET("/payment-request/:hash/votes", daoResource.GetPaymentRequestVotes)
cfundGroup.GET("/payment-request/:hash/trend", daoResource.GetPaymentRequestTrend)
cfundGroup.GET("/votes/excluded", daoResource.GetExcludedVotesForCycle)
searchResource := resource.NewSearchResource(container.GetAddressService(), container.GetBlockService(), container.GetDaoService())
r.GET("/search", searchResource.Search)
supplyResource := resource.NewSupplyResource(container.GetBlockService(), container.GetDaoConsensusService())
r.GET("/supply", supplyResource.GetSupply)
r.NoRoute(func(c *gin.Context) {
c.JSON(404, gin.H{"code": 404, "message": "Resource not found"})
})
_ = r.Run(fmt.Sprintf(":%d", config.Get().Server.Port))
}