Documentation
¶
Index ¶
- Constants
- func CallAPI(url, method string, header map[string]string, body io.Reader) (json.RawMessage, error)
- func GetLastUpdatedTS(db *gorm.DB, api APIConfig, dataModel interface{}) int64
- func InitOAuth2ClientCredentials(cf OAuth2Config)
- func SyncToCSV(fileName string, api APIConfig) (int64, error)
- func SyncToDB(db *gorm.DB, api APIConfig, dataModel interface{}) (int64, error)
- func SyncToFile(mode string, fileName string, api APIConfig) (int64, error)
- func SyncToModel(api APIConfig, dataModel interface{}) error
- func UnmarshalRows(src []interface{}, dst interface{}) error
- type APIConfig
- type APIResult
- type DataResult
- type OAuth2Client
- func (c *OAuth2Client) GetAllRows(apiPath string, pageSize int) ([]interface{}, error)
- func (c *OAuth2Client) GetRows(apiPath string, pageNum, pageSize int) (DataResult, error)
- func (c *OAuth2Client) HttpGet(url string) (json.RawMessage, error)
- func (c *OAuth2Client) HttpRequest(url, method string, header map[string]string, body io.Reader) (json.RawMessage, error)
- type OAuth2Config
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 GetLastUpdatedTS ¶
func InitOAuth2ClientCredentials ¶
func InitOAuth2ClientCredentials(cf OAuth2Config)
Init 初始化 OAuth2 应用
func SyncToModel ¶
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) ParamEncode ¶
func (*APIConfig) SetDefault ¶
func (api *APIConfig) SetDefault()
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 (*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
Click to show internal directories.
Click to hide internal directories.