main.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  1. package main
  2. import (
  3. "fmt"
  4. "net/http"
  5. "github.com/gin-gonic/gin"
  6. )
  7. type queryHeader struct {
  8. MyHeader string `header:"my_header"`
  9. MyDemo string `header:"my_demo"`
  10. XChain string `header:"X-Chain"`
  11. Key string `header:"x-api-key"`
  12. }
  13. type queryBody struct {
  14. Name string `json:"name"`
  15. Age int `json:"age"`
  16. Sex int `json:"sex"`
  17. }
  18. type Req struct {
  19. Data []ClassReq `json:"data"`
  20. }
  21. type ClassReq struct {
  22. SeriesName string `json:"seriesName"`
  23. SeriesIssuer string `json:"seriesIssuer"`
  24. ExternalUrl string `json:"externalUrl"`
  25. SeriesDes string `json:"seriesDes"`
  26. SeriesId []string `json:"seriesId"`
  27. TotalDNA int64 `json:"totalDNA"`
  28. AssetContracts string `json:"asset_contracts"`
  29. }
  30. type queryParameter struct {
  31. // Year int `form:"year"`
  32. // Month int `form:"month"`
  33. Code string `form:"code"`
  34. }
  35. type queryUri struct {
  36. Id int `uri:"id"`
  37. Name string `uri:"name"`
  38. }
  39. func bindUri(context *gin.Context) {
  40. var q queryUri
  41. err := context.ShouldBindUri(&q)
  42. if err != nil {
  43. context.JSON(http.StatusBadRequest, gin.H{
  44. "result": err.Error(),
  45. })
  46. return
  47. }
  48. context.JSON(http.StatusOK, gin.H{
  49. "result": "绑定成功",
  50. "uri": q,
  51. })
  52. }
  53. func bindQuery(context *gin.Context) {
  54. var q queryParameter
  55. err := context.ShouldBindQuery(&q)
  56. if err != nil {
  57. context.JSON(http.StatusBadRequest, gin.H{
  58. "result": err.Error(),
  59. })
  60. return
  61. }
  62. context.JSON(http.StatusOK, gin.H{
  63. "result": "绑定成功",
  64. "query": q,
  65. })
  66. }
  67. func bindBody(context *gin.Context) {
  68. fmt.Println(context.Request.Body)
  69. var q Req
  70. err := context.ShouldBindJSON(&q)
  71. if err != nil {
  72. fmt.Println(err.Error())
  73. context.JSON(http.StatusBadRequest, gin.H{
  74. "result": err.Error(),
  75. })
  76. return
  77. }
  78. fmt.Printf("%v\n", q)
  79. context.JSON(http.StatusOK, gin.H{
  80. "result": "绑定成功",
  81. "body": q,
  82. })
  83. }
  84. func bindhead(context *gin.Context) {
  85. var q queryHeader
  86. err := context.ShouldBindHeader(&q)
  87. if err != nil {
  88. context.JSON(http.StatusBadRequest, gin.H{
  89. "result": err.Error(),
  90. })
  91. return
  92. }
  93. context.JSON(http.StatusUnauthorized, gin.H{
  94. "result": "绑定成功",
  95. "header": q,
  96. })
  97. }
  98. func main() {
  99. srv := gin.Default()
  100. srv.GET("/binding/header", bindhead)
  101. srv.POST("/binding/body", bindBody)
  102. srv.GET("/binding/query", bindQuery)
  103. srv.GET("/binding/:id/:name", bindUri)
  104. // srv.Use(CORSMiddleware())
  105. srv.Run(":9999")
  106. }
  107. func CORSMiddleware() gin.HandlerFunc {
  108. // 配置跨域
  109. return func(c *gin.Context) {
  110. // 允许的请求源,这里设置为允许所有来源
  111. c.Writer.Header().Set("Access-Control-Allow-Origin", "*")
  112. // 允许的请求方法
  113. c.Writer.Header().Set("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS")
  114. // 允许的请求头
  115. // c.Writer.Header().Set("Access-Control-Allow-Headers", "Authorization, Content-Type,Accept-Language,X-Requested-With,Global")
  116. c.Writer.Header().Set("Access-Control-Allow-Headers", "Authorization, Content-Type,Accept-Language,X-Requested-With,Global,Accept,Accept-Encoding,Accept-Language,Cache-Control,Connection,Host,Origin,Pragma,Referer,User-Agent,X-Chain")
  117. // 处理 OPTIONS 请求
  118. if c.Request.Method == http.MethodOptions {
  119. // 返回成功状态码
  120. c.AbortWithStatus(http.StatusOK)
  121. return
  122. }
  123. c.Next()
  124. }
  125. }
  126. var html = `<!DOCTYPE html>
  127. <html lang="en">
  128. <head>
  129. <meta charset="UTF-8" />
  130. <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  131. <meta
  132. name="keywords"
  133. content="Avata api,AVATA API,Avata 平台,Avata v3 API,Avata console 平台,Avata 服务,AVATA 平台,AVATA 服务平台,AVATA API 平台,Avata 控制台,边界智能Avata,文昌链接口平台,文昌链API,多链API服务平台,跨链API服务平台,区块链API服务"
  134. />
  135. <meta
  136. name="description"
  137. content="AVATA 是由边界智能基于区块链底层核心技术以及支持复杂分布式 商业应用的经验,自主研发的多链 / 跨链 NFT/ 元宇宙应用 API 服务平台。"
  138. />
  139. <meta
  140. property="og:description"
  141. content="「Avata」由边界智能自主研发、将区块链底层复杂交互逻辑封装成的一款多链/跨链 NFT/元宇宙应用 API 服务平台型产品。助力开发者和企业打造开放、多元的分布式商业形态。"
  142. />
  143. <meta property="og:title" content="Avata 服务平台-边界智能" />
  144. <meta
  145. property="og:image"
  146. content="https://www.bianjie.ai/resources/Avata/Avata_share.png"
  147. />
  148. <meta
  149. name="viewport"
  150. content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"
  151. />
  152. <title>Avata 服务平台</title>
  153. <link rel="icon" href="/logo.png" type="image/x-icon" />
  154. <link rel="stylesheet" href="/umi.0cebcf47.css" />
  155. <script>
  156. window.routerBase = "/";
  157. </script>
  158. <script>
  159. //! umi version: 3.5.21
  160. </script>
  161. </head>
  162. <!-- <script>
  163. var _hmt = _hmt || [];
  164. (function () {
  165. var hm = document.createElement('script');
  166. hm.src = 'https://hm.baidu.com/hm.js?ae855a2ddad87d95ed80d0de0b180679';
  167. var s = document.getElementsByTagName('script')[0];
  168. s.parentNode.insertBefore(hm, s);
  169. })();
  170. </script> -->
  171. <body>
  172. <noscript>
  173. <div class="noscript-container">
  174. Hi there! Please
  175. <div class="noscript-enableJS">
  176. <a
  177. href="https://www.enablejavascript.io/en"
  178. target="_blank"
  179. rel="noopener noreferrer"
  180. >
  181. <b>enable Javascript</b>
  182. </a>
  183. </div>
  184. in your browser to use Ant Design, Out-of-the-box mid-stage front/design
  185. solution!
  186. </div>
  187. </noscript>
  188. <div id="root">
  189. <style>
  190. html,
  191. body,
  192. #root {
  193. height: 100%;
  194. margin: 0;
  195. padding: 0;
  196. }
  197. #root {
  198. background-repeat: no-repeat;
  199. background-size: 100% auto;
  200. }
  201. .noscript-container {
  202. display: flex;
  203. align-content: center;
  204. justify-content: center;
  205. margin-top: 90px;
  206. font-size: 20px;
  207. font-family: "Lucida Sans", "Lucida Sans Regular", "Lucida Grande",
  208. "Lucida Sans Unicode", Geneva, Verdana, sans-serif;
  209. }
  210. .noscript-enableJS {
  211. padding-right: 3px;
  212. padding-left: 3px;
  213. }
  214. .page-loading-warp {
  215. display: flex;
  216. align-items: center;
  217. justify-content: center;
  218. padding: 98px;
  219. }
  220. .ant-spin {
  221. position: absolute;
  222. display: none;
  223. -webkit-box-sizing: border-box;
  224. box-sizing: border-box;
  225. margin: 0;
  226. padding: 0;
  227. color: rgba(0, 0, 0, 0.65);
  228. color: #1890ff;
  229. font-size: 14px;
  230. font-variant: tabular-nums;
  231. line-height: 1.5;
  232. text-align: center;
  233. list-style: none;
  234. opacity: 0;
  235. -webkit-transition: -webkit-transform 0.3s
  236. cubic-bezier(0.78, 0.14, 0.15, 0.86);
  237. transition: -webkit-transform 0.3s
  238. cubic-bezier(0.78, 0.14, 0.15, 0.86);
  239. transition: transform 0.3s cubic-bezier(0.78, 0.14, 0.15, 0.86);
  240. transition: transform 0.3s cubic-bezier(0.78, 0.14, 0.15, 0.86),
  241. -webkit-transform 0.3s cubic-bezier(0.78, 0.14, 0.15, 0.86);
  242. -webkit-font-feature-settings: "tnum";
  243. font-feature-settings: "tnum";
  244. }
  245. .ant-spin-spinning {
  246. position: static;
  247. display: inline-block;
  248. opacity: 1;
  249. }
  250. .ant-spin-dot {
  251. position: relative;
  252. display: inline-block;
  253. width: 20px;
  254. height: 20px;
  255. font-size: 20px;
  256. }
  257. .ant-spin-dot-item {
  258. position: absolute;
  259. display: block;
  260. width: 9px;
  261. height: 9px;
  262. background-color: #1890ff;
  263. border-radius: 100%;
  264. -webkit-transform: scale(0.75);
  265. -ms-transform: scale(0.75);
  266. transform: scale(0.75);
  267. -webkit-transform-origin: 50% 50%;
  268. -ms-transform-origin: 50% 50%;
  269. transform-origin: 50% 50%;
  270. opacity: 0.3;
  271. -webkit-animation: antspinmove 1s infinite linear alternate;
  272. animation: antSpinMove 1s infinite linear alternate;
  273. }
  274. .ant-spin-dot-item:nth-child(1) {
  275. top: 0;
  276. left: 0;
  277. }
  278. .ant-spin-dot-item:nth-child(2) {
  279. top: 0;
  280. right: 0;
  281. -webkit-animation-delay: 0.4s;
  282. animation-delay: 0.4s;
  283. }
  284. .ant-spin-dot-item:nth-child(3) {
  285. right: 0;
  286. bottom: 0;
  287. -webkit-animation-delay: 0.8s;
  288. animation-delay: 0.8s;
  289. }
  290. .ant-spin-dot-item:nth-child(4) {
  291. bottom: 0;
  292. left: 0;
  293. -webkit-animation-delay: 1.2s;
  294. animation-delay: 1.2s;
  295. }
  296. .ant-spin-dot-spin {
  297. -webkit-transform: rotate(45deg);
  298. -ms-transform: rotate(45deg);
  299. transform: rotate(45deg);
  300. -webkit-animation: antrotate 1.2s infinite linear;
  301. animation: antRotate 1.2s infinite linear;
  302. }
  303. .ant-spin-lg .ant-spin-dot {
  304. width: 32px;
  305. height: 32px;
  306. font-size: 32px;
  307. }
  308. .ant-spin-lg .ant-spin-dot i {
  309. width: 14px;
  310. height: 14px;
  311. }
  312. @media all and (-ms-high-contrast: none), (-ms-high-contrast: active) {
  313. .ant-spin-blur {
  314. background: #fff;
  315. opacity: 0.5;
  316. }
  317. }
  318. @-webkit-keyframes antSpinMove {
  319. to {
  320. opacity: 1;
  321. }
  322. }
  323. @keyframes antSpinMove {
  324. to {
  325. opacity: 1;
  326. }
  327. }
  328. @-webkit-keyframes antRotate {
  329. to {
  330. -webkit-transform: rotate(405deg);
  331. transform: rotate(405deg);
  332. }
  333. }
  334. @keyframes antRotate {
  335. to {
  336. -webkit-transform: rotate(405deg);
  337. transform: rotate(405deg);
  338. }
  339. }
  340. </style>
  341. <!-- <div
  342. style="
  343. display: flex;
  344. flex-direction: column;
  345. align-items: center;
  346. justify-content: center;
  347. height: 100%;
  348. min-height: 420px;
  349. "
  350. >
  351. <img
  352. src="/pro_icon.svg"
  353. alt="logo"
  354. width="256"
  355. />
  356. <div class="page-loading-warp">
  357. <div class="ant-spin ant-spin-lg ant-spin-spinning">
  358. <span class="ant-spin-dot ant-spin-dot-spin"
  359. ><i class="ant-spin-dot-item"></i><i class="ant-spin-dot-item"></i
  360. ><i class="ant-spin-dot-item"></i><i class="ant-spin-dot-item"></i
  361. ></span>
  362. </div>
  363. </div>
  364. <div
  365. style="display: flex; align-items: center; justify-content: center"
  366. >
  367. <img
  368. src="https://gw.alipayobjects.com/zos/rmsportal/KDpgvguMpGfqaHPjicRK.svg"
  369. width="32"
  370. style="margin-right: 8px"
  371. />
  372. Ant Design
  373. </div>
  374. </div> -->
  375. </div>
  376. <script src="/umi.12fd7d0e.js"></script>
  377. </body>
  378. </html>`