1
package api
2

3
import (
4
	"net/http"
5
	"time"
6

7
	"github.com/chenjiandongx/ginprom"
8
	"github.com/gin-gonic/gin"
9
	"github.com/prometheus/client_golang/prometheus/promhttp"
10
	ginSwagger "github.com/swaggo/gin-swagger"
11
	"github.com/swaggo/gin-swagger/swaggerFiles"
12
	"github.com/trustwallet/golibs/middleware"
13
	"github.com/trustwallet/watchmarket/api/endpoint"
14
	_ "github.com/trustwallet/watchmarket/docs"
15
	"github.com/trustwallet/watchmarket/services/controllers"
16
)
17

18
func SetupBasicAPI(engine *gin.Engine) {
19 1
	engine.GET("/", func(c *gin.Context) { c.JSON(http.StatusOK, "Watchmarket API") })
20 1
	engine.GET("/metrics", ginprom.PromHandler(promhttp.Handler()))
21
}
22

23
func SetupSwaggerAPI(engine *gin.Engine) {
24 1
	engine.GET("swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
25
}
26

27
func SetupInfoAPI(engine *gin.Engine, info controllers.InfoController, d time.Duration) {
28 1
	engine.GET("v2/market/info/:id",
29 1
		middleware.CacheControl(d, endpoint.GetCoinInfoHandlerV2(info)))
30

31 1
	engine.GET("v1/market/info",
32 1
		middleware.CacheControl(d, endpoint.GetCoinInfoHandler(info)))
33
}
34

35
func SetupChartsAPI(engine *gin.Engine, charts controllers.ChartsController, d time.Duration) {
36 1
	engine.GET("v2/market/charts/:id",
37 1
		middleware.CacheControl(d, endpoint.GetChartsHandlerV2(charts)))
38

39 1
	engine.GET("v1/market/charts",
40 1
		middleware.CacheControl(d, endpoint.GetChartsHandler(charts)))
41
}
42

43
func SetupTickersAPI(engine *gin.Engine, tickers controllers.TickersController, d time.Duration) {
44 1
	engine.POST("v2/market/tickers",
45 1
		middleware.CacheControl(d, endpoint.PostTickersHandlerV2(tickers)))
46

47 1
	engine.GET("v2/market/ticker/:id",
48 1
		middleware.CacheControl(d, endpoint.GetTickerHandlerV2(tickers)))
49

50 1
	engine.GET("v2/market/tickers/:assets",
51 1
		middleware.CacheControl(d, endpoint.GetTickersHandlerV2(tickers)))
52

53 1
	engine.POST("v1/market/ticker",
54 1
		middleware.CacheControl(d, endpoint.GetTickersHandler(tickers)))
55
}
56

57
func SetupRatesAPI(engine *gin.Engine, rates controllers.RatesController) {
58 0
	engine.GET("/v1/market/rate", endpoint.GetRate(rates))
59
}

Read our documentation on viewing source code .

Loading