| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- package api
- import (
- "bytes"
- "encoding/json"
- "io"
- "net/http"
- )
- type BlockchainApi struct {
- baseUrl string
- }
- func NewBlockchainApi() *BlockchainApi {
- return &BlockchainApi{
- baseUrl: "http://web.410eth.com:8888",
- }
- }
- func HttpPost(url string, jsonData []byte) (string, error) {
- resp, err := http.Post(url, "application/json", bytes.NewBuffer(jsonData))
- if err != nil {
- return "", err
- }
- defer resp.Body.Close()
- body, err := io.ReadAll(resp.Body)
- if err != nil {
- return "", err
- }
- return string(body), nil
- }
- func (a *BlockchainApi) HelloWorld(request HelloWorldRequest) (string, error) {
- url := a.baseUrl
- jsonData, _ := json.Marshal(request)
- return HttpPost(url, jsonData)
- }
- func (a *BlockchainApi) V2LpCountByChainId(request V2LpCountByChainIdRequest) (V2LpCountByChainIdResult, error) {
- url := a.baseUrl + "/v2-lp/countByChainId"
- jsonData, _ := json.Marshal(request)
- rstStr, err := HttpPost(url, jsonData)
- if err != nil {
- return V2LpCountByChainIdResult{}, err
- }
- result := V2LpCountByChainIdResult{
- Origin: rstStr,
- }
- json.Unmarshal([]byte(rstStr), &result)
- return result, err
- }
|