sdk

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 24, 2023 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultScope   = "ECNU-Basic"
	DefaultBaseURL = "https://api.ecnu.edu.cn"
	DefaultTimeout = 10
)
View Source
const (
	MAXPageSIZE = 10000
)

Variables

This section is empty.

Functions

func CallAPI

func CallAPI(url, method string, header map[string]string, body io.Reader) (json.RawMessage, error)

func GetLastUpdatedTS

func GetLastUpdatedTS(db *gorm.DB, api APIConfig, dataModel interface{}) int64

func InitOAuth2ClientCredentials

func InitOAuth2ClientCredentials(cf OAuth2Config)

Init 初始化 OAuth2 应用

func SyncToCSV

func SyncToCSV(fileName string, api APIConfig) (int64, error)

func SyncToDB

func SyncToDB(db *gorm.DB, api APIConfig, dataModel interface{}) (int64, error)

func SyncToFile

func SyncToFile(mode string, fileName string, api APIConfig) (int64, error)

func SyncToModel

func SyncToModel(api APIConfig, dataModel interface{}) error

func UnmarshalRows

func UnmarshalRows(src []interface{}, dst interface{}) error

UnmarshalRows 将一个 []interface{} 的数据映射到一个 struct 数组

Types

type APIConfig

type APIConfig struct {
	APIPath        string `json:"api_path"`
	PageSize       int    `json:"page_size"`
	BatchSize      int    `json:"batch_size"`
	UpdatedAtField string
	// contains filtered or unexported fields
}

func (*APIConfig) AddParam

func (api *APIConfig) AddParam(key, value string)

func (*APIConfig) DelParam

func (api *APIConfig) DelParam(key string)

func (*APIConfig) ParamEncode

func (api *APIConfig) ParamEncode() string

func (*APIConfig) SetDefault

func (api *APIConfig) SetDefault()

func (*APIConfig) SetParam

func (api *APIConfig) SetParam(key, value string)

type APIResult

type APIResult struct {
	ErrCode   int64           `json:"errCode"`
	ErrMsg    string          `json:"errMsg"`
	RequestId string          `json:"requestId"`
	Data      json.RawMessage `json:"data"`
}

APIResult 数据响应结构 https://developer.ecnu.edu.cn/doc/#/architecture/design?id=%e6%95%b0%e6%8d%ae%e5%93%8d%e5%ba%94%e7%bb%93%e6%9e%84

type DataResult

type DataResult struct {
	TotalNum int           `json:"totalNum"`
	PageSize int           `json:"pageSize"`
	PageNum  int           `json:"pageNum"`
	Rows     []interface{} `json:"rows"`
}

DataResult

type OAuth2Client

type OAuth2Client struct {
	Client     *http.Client
	BaseUrl    string
	RetryCount int
	Debug      bool
	// contains filtered or unexported fields
}

func GetOpenAPIClient

func GetOpenAPIClient() *OAuth2Client

GetOpenAPIClient 获取接口的Client信息

func (*OAuth2Client) GetAllRows

func (c *OAuth2Client) GetAllRows(apiPath string, pageSize int) ([]interface{}, error)

GetAllRows

func (*OAuth2Client) GetRows

func (c *OAuth2Client) GetRows(apiPath string, pageNum, pageSize int) (DataResult, error)

GetRows

func (*OAuth2Client) HttpGet

func (c *OAuth2Client) HttpGet(url string) (json.RawMessage, error)

HttpGet 通用GET请求

func (*OAuth2Client) HttpRequest

func (c *OAuth2Client) HttpRequest(url, method string, header map[string]string, body io.Reader) (json.RawMessage, error)

通用 http 请求 todo

type OAuth2Config

type OAuth2Config struct {
	ClientId     string   `json:"client_id"`
	ClientSecret string   `json:"client_secret"`
	BaseUrl      string   `json:"base_url"`
	Scopes       []string `json:"scopes"`
	Timeout      int64    `json:"timeout"`
	Debug        bool     `json:"debug"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL