Skip to content

Commit

Permalink
fix golint
Browse files Browse the repository at this point in the history
  • Loading branch information
bububa committed Jul 23, 2021
1 parent 8ffe0b8 commit e78f8bf
Show file tree
Hide file tree
Showing 65 changed files with 831 additions and 325 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Go

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:

build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.16

- name: Build
run: go build -v ./...

- name: Test
env:
APPKEY: ${{ secrets.APPKEY }}
SECRET: ${{ secrets.APP_SECRET }}
run: go test -v ./...
15 changes: 15 additions & 0 deletions .github/workflows/goformatter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Golang Formatter
on: [pull_request]
jobs:
build:
name: Golang Formatter
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
with:
fetch-depth: 0
- name: Golang Formatter
uses: sladyn98/auto-go-format@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

33 changes: 33 additions & 0 deletions .github/workflows/goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: goreleaser

on:
push:
tags:
- '*'

jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
-
name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.16
-
name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
# either 'goreleaser' (default) or 'goreleaser-pro'
distribution: goreleaser
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Your GoReleaser Pro key, if you are using the 'goreleaser-pro' distribution
# GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }}
9 changes: 9 additions & 0 deletions .github/workflows/goreportcard.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: GoReportCard
on: [push, pull_request]
jobs:
build:
name: GoReportCard
runs-on: ubuntu-latest
steps:
- name: GoReportCard
uses: creekorful/goreportcard-action@v1.0
28 changes: 28 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# This is an example .goreleaser.yml file with some sane defaults.
# Make sure to check the documentation at http://goreleaser.com
project_name: "mapi"
before:
hooks:
# You may remove this if you don't use go modules.
- go mod tidy
# you may remove this if you don't need go generate
- go generate ./...
builds:
- skip: true
archives:
- replacements:
darwin: Darwin
linux: Linux
windows: Windows
386: i386
amd64: x86_64
checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ .Tag }}-next"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# 快手磁力引擎MarketingAPI Golang SDK

[![Go Reference](https://pkg.go.dev/badge/github.com/bububa/kwai-marketing-api.svg)](https://pkg.go.dev/github.com/bububa/kwai-marketing-api)
[![Go](https://github.com/bububa/kwai-marketing-api/actions/workflows/go.yml/badge.svg)](https://github.com/bububa/kwai-marketing-api/actions/workflows/go.yml)
[![goreleaser](https://github.com/bububa/kwai-marketing-api/actions/workflows/goreleaser.yml/badge.svg)](https://github.com/bububa/kwai-marketing-api/actions/workflows/goreleaser.yml)
[![GitHub go.mod Go version of a Go module](https://img.shields.io/github/go-mod/go-version/bububa/kwai-marketing-api.svg)](https://github.com/bububa/kwai-marketing-api)
[![GoReportCard](https://goreportcard.com/badge/github.com/bububa/kwai-marketing-api)](https://goreportcard.com/report/github.com/bububa/kwai-marketing-api)
[![GitHub license](https://img.shields.io/github/license/bububa/kwai-marketing-api.svg)](https://github.com/bububa/kwai-marketing-api/blob/master/LICENSE)
[![GitHub release](https://img.shields.io/github/release/bububa/kwai-marketing-api.svg)](https://GitHub.com/bububa/kwai-marketing-api/releases/)


- Oauth2 授权 (api/oauth)
- 生成授权链接 [ Url(clt *core.SDKClient, req *oauth.UrlRequest) string ]
- 获取AccessToken [ AccessToken(clt *core.SDKClient, authCode String) (*oauth.AccessTokenResponse, error) ]
Expand Down
2 changes: 2 additions & 0 deletions api/advertiser/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Package advertiser 广告主相关API
package advertiser
2 changes: 1 addition & 1 deletion api/advertiser/fund_daily_flows.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"github.com/bububa/kwai-marketing-api/model/advertiser"
)

// 获取广告账户流水信息
// FundDailyFlows 获取广告账户流水信息
func FundDailyFlows(clt *core.SDKClient, accessToken string, req *advertiser.FundDailyFlowsRequest) (*advertiser.FundDailyFlowsResponse, error) {
var resp advertiser.FundDailyFlowsResponse
err := clt.Get(accessToken, req, &resp)
Expand Down
2 changes: 1 addition & 1 deletion api/advertiser/fund_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"github.com/bububa/kwai-marketing-api/model/advertiser"
)

// 获取广告账户余额信息
// FundGet 获取广告账户余额信息
func FundGet(clt *core.SDKClient, accessToken string, advertiserID int64) (float64, error) {
req := &advertiser.FundGetRequest{
AdvertiserID: advertiserID,
Expand Down
2 changes: 1 addition & 1 deletion api/advertiser/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"github.com/bububa/kwai-marketing-api/model/advertiser"
)

// 获取广告账户信息
// Info 获取广告账户信息
func Info(clt *core.SDKClient, accessToken string, advertiserID int64) (*advertiser.Info, error) {
req := &advertiser.InfoRequest{
AdvertiserID: advertiserID,
Expand Down
2 changes: 1 addition & 1 deletion api/oauth/access_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"github.com/bububa/kwai-marketing-api/model/oauth"
)

// 获取token
// AccessToken 获取token
// 利用授权码auth_code,请求快手服务器,获取access_token和refresh_token及当前账户的广告主ID。
func AccessToken(clt *core.SDKClient, authCode string) (*oauth.AccessTokenResponse, error) {
req := &oauth.AccessTokenRequest{
Expand Down
2 changes: 2 additions & 0 deletions api/oauth/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Package oauth Oauth2授权相关API
package oauth
2 changes: 1 addition & 1 deletion api/oauth/refresh_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"github.com/bububa/kwai-marketing-api/model/oauth"
)

// 刷新tonken
// RefreshToken 刷新tonken
// 请求快手服务器,刷新access_token和refresh_token及token过期时间。
func RefreshToken(clt *core.SDKClient, refreshToken string) (*oauth.AccessTokenResponse, error) {
req := &oauth.RefreshTokenRequest{
Expand Down
2 changes: 1 addition & 1 deletion api/oauth/url.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"github.com/bububa/kwai-marketing-api/model/oauth"
)

// 生成授权链接
// Url 生成授权链接
func Url(clt *core.SDKClient, req *oauth.UrlRequest) string {
req.AppID = clt.AppID()
return clt.GetUrl(req)
Expand Down
2 changes: 1 addition & 1 deletion api/report/account_report.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"github.com/bububa/kwai-marketing-api/model/report"
)

// 广告主数据(实时)
// AccountReport 广告主数据(实时)
func AccountReport(clt *core.SDKClient, accessToken string, req *report.AccountReportRequest) (*report.ReportResponse, error) {
var resp report.ReportResponse
err := clt.Post(accessToken, req, &resp)
Expand Down
2 changes: 1 addition & 1 deletion api/report/agent_report.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"github.com/bububa/kwai-marketing-api/model/report"
)

// 代理商数据(t-1数据需要第二天9点以后获取)
// AgentReport 代理商数据(t-1数据需要第二天9点以后获取)
func AgentReport(clt *core.SDKClient, accessToken string, req *report.AgentReportRequest) (*report.AgentReportResponse, error) {
var resp report.AgentReportResponse
err := clt.Post(accessToken, req, &resp)
Expand Down
2 changes: 1 addition & 1 deletion api/report/audience_report.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"github.com/bububa/kwai-marketing-api/model/report"
)

// 人群分析报表
// AgentReport 人群分析报表
func AudienceReport(clt *core.SDKClient, accessToken string, req *report.AudienceReportRequest) (*report.ReportResponse, error) {
var resp report.ReportResponse
err := clt.Post(accessToken, req, &resp)
Expand Down
2 changes: 1 addition & 1 deletion api/report/campaign_report.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"github.com/bububa/kwai-marketing-api/model/report"
)

// 广告计划数据(实时)
// CampaignReport 广告计划数据(实时)
func CampaignReport(clt *core.SDKClient, accessToken string, req *report.CampaignReportRequest) (*report.ReportResponse, error) {
var resp report.ReportResponse
err := clt.Post(accessToken, req, &resp)
Expand Down
2 changes: 1 addition & 1 deletion api/report/creative_report.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"github.com/bububa/kwai-marketing-api/model/report"
)

// 广告创意数据-自定义
// CreativeReport 广告创意数据-自定义
func CreativeReport(clt *core.SDKClient, accessToken string, req *report.CreativeReportRequest) (*report.ReportResponse, error) {
var resp report.ReportResponse
err := clt.Post(accessToken, req, &resp)
Expand Down
2 changes: 2 additions & 0 deletions api/report/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Package report 数据报表相关API
package report
2 changes: 1 addition & 1 deletion api/report/material_report.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"github.com/bububa/kwai-marketing-api/model/report"
)

// 素材报表
// MaterialReport 素材报表
func MaterialReport(clt *core.SDKClient, accessToken string, req *report.MaterialReportRequest) (*report.ReportResponse, error) {
var resp report.ReportResponse
err := clt.Post(accessToken, req, &resp)
Expand Down
2 changes: 1 addition & 1 deletion api/report/merchant_detail_report.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"github.com/bububa/kwai-marketing-api/model/report"
)

// 小店通转化数据报表
// MerchantDetailReport 小店通转化数据报表
func MerchantDetailReport(clt *core.SDKClient, accessToken string, req *report.MerchantDetailReportRequest) (*report.MerchantDetailReportResponse, error) {
var resp report.MerchantDetailReportResponse
err := clt.Post(accessToken, req, &resp)
Expand Down
2 changes: 1 addition & 1 deletion api/report/program_creative_report.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"github.com/bububa/kwai-marketing-api/model/report"
)

// 程序化创意2.0数据
// ProgramCreativeReport 程序化创意2.0数据
func ProgramCreativeReport(clt *core.SDKClient, accessToken string, req *report.ProgramCreativeReportRequest) (*report.ReportResponse, error) {
var resp report.ReportResponse
err := clt.Post(accessToken, req, &resp)
Expand Down
2 changes: 1 addition & 1 deletion api/report/unit_report.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"github.com/bububa/kwai-marketing-api/model/report"
)

// 广告组数据
// UnitReport 广告组数据
func UnitReport(clt *core.SDKClient, accessToken string, req *report.UnitReportRequest) (*report.ReportResponse, error) {
var resp report.ReportResponse
err := clt.Post(accessToken, req, &resp)
Expand Down
2 changes: 1 addition & 1 deletion api/track/activate.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/bububa/kwai-marketing-api/model/track"
)

// 转化回传API
// Activate 转化回传API
func Activate(req *track.ActivateRequest) error {
reqUrl := fmt.Sprintf("%s?%s", core.ACTIVATE_URL, req.Encode())
httpReq, err := http.NewRequest("GET", reqUrl, nil)
Expand Down
2 changes: 2 additions & 0 deletions api/track/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Package track 数据上报管理相关API
package track
16 changes: 9 additions & 7 deletions core/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,45 +10,47 @@ import (
"github.com/bububa/kwai-marketing-api/model"
)

// sdkclient object
// SDKClient api client
type SDKClient struct {
appID int64
secret string
debug bool
}

// init sdk client
// NewSDKClient init sdk client
func NewSDKClient(appID int64, secret string) *SDKClient {
return &SDKClient{
appID: appID,
secret: secret,
}
}

// set debug mode
// SetDebug set debug mode
func (c *SDKClient) SetDebug(debug bool) {
c.debug = debug
}

// appID getter
// AppID appID getter
func (c *SDKClient) AppID() int64 {
return c.appID
}

// secret getter
// Secret secret getter
func (c *SDKClient) Secret() string {
return c.secret
}

// PostUrl post请求地址
func (c *SDKClient) PostUrl(req model.PostRequest) string {
return fmt.Sprintf("%s/%s", BASE_URL, req.Url())
}

// GetUrl get请求地址
func (c *SDKClient) GetUrl(req model.GetRequest) string {
return fmt.Sprintf("%s/%s?%s", BASE_URL, req.Url(), req.Encode())
}

// execute post api request
// Post execute post api request
func (c *SDKClient) Post(accessToken string, req model.PostRequest, resp interface{}) error {
var reqResp model.BaseResponse
err := c.post(accessToken, c.PostUrl(req), req.Encode(), &reqResp)
Expand All @@ -67,7 +69,7 @@ func (c *SDKClient) Post(accessToken string, req model.PostRequest, resp interfa
return nil
}

// execute get api request
// Get execute get api request
func (c *SDKClient) Get(accessToken string, req model.GetRequest, resp interface{}) error {
var reqResp model.BaseResponse
err := c.get(accessToken, c.GetUrl(req), &reqResp)
Expand Down
4 changes: 3 additions & 1 deletion core/const.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package core

const (
BASE_URL = "https://ad.e.kuaishou.com/rest/openapi"
// BASE_URL api gateway
BASE_URL = "https://ad.e.kuaishou.com/rest/openapi"
// ACTIVATE_URL 上报地址
ACTIVATE_URL = "http://ad.partner.gifshow.com/track/activate"
)
2 changes: 2 additions & 0 deletions core/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Package core 核心方法
package core
2 changes: 1 addition & 1 deletion doc.go
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// 磁力引擎API
// Package mapi 磁力引擎API
package mapi
2 changes: 2 additions & 0 deletions model/advertiser/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Package advertiser 广告主相关API结构体
package advertiser
Loading

0 comments on commit e78f8bf

Please sign in to comment.