digital_lib.go 1.2 KB
package digitalLib

import (
	"github.com/beego/beego/v2/core/logs"
	"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/infrastructure/api"
	"net/http"
	"time"
)

type DigitalLib struct {
	Token string
	api.BaseServiceGateway
}

func (gateway *DigitalLib) WithToken(token string) *DigitalLib {
	gateway.Token = token
	return gateway
}

func (gateway *DigitalLib) DefaultHeader() http.Header {
	var header = make(map[string][]string)
	header["x-mmm-accesstoken"] = []string{gateway.Token}
	return header
}

func NewDigitalLib(host string) *DigitalLib {
	gt := api.NewBaseServiceGateway(host)
	gt.ConnectTimeout = 360 * time.Second
	gt.ReadWriteTimeout = 360 * time.Second
	gt.Interceptor = func(msg string) {
		//log.Logger.Info(msg)
		logs.Debug(msg)
	}
	gt.ServiceName = "【数控中心】"
	return &DigitalLib{
		BaseServiceGateway: gt,
	}
}

func (gateway *DigitalLib) SyncNotice(param RequestSyncNotice) (*DataSyncNotice, error) {
	url := gateway.Host() + "/api/sync/notice"
	method := "post"
	var data DataSyncNotice
	err := gateway.FastDoRequest(url, method, param.Body, &data, api.WithHeader(gateway.DefaultHeader()))
	if err != nil {
		return nil, err
	}
	return &data, nil
}