Skip to content

Commit

Permalink
Add linter & fix warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
olivier-lando committed Apr 21, 2021
1 parent 53e6749 commit 2d886f2
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 88 deletions.
96 changes: 96 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
run:
concurrency: 8
deadline: 1m
issues-exit-code: 1
tests: true
skip-files:
- mock_*.go
output:
format: colored-line-number
print-issued-lines: true
print-linter-name: true
linters-settings:
errcheck:
check-type-assertions: true
gocognit:
min-complexity: 15
goconst:
min-len: 3
min-occurrences: 3
gocritic:
enabled-checks:
- appendCombine
- badCall
- badCond
- boolExprSimplify
- codegenComment
- commentFormatting
- commentedOutCode
- deprecatedComment
- dupImport
- emptyFallthrough
- emptyStringTest
- equalFold
- evalOrder
- exitAfterDefer
- flagName
- hexLiteral
- indexAlloc
- initClause
- methodExprCall
- nestingReduce
- newDeref
- nilValReturn
- offBy1
- ptrToRefParam
- rangeExprCopy
- regexpPattern
- sloppyReassign
- stringXbytes
- truncateCmp
- typeAssertChain
- typeUnparen
- underef
- unnecessaryBlock
- valSwap
- weakCond
- wrapperFunc
- yodaStyleExpr
gocyclo:
min-complexity: 10
govet:
check-shadowing: false
lll:
line-length: 120
tab-width: 4
nestif:
min-complexity: 5
linters:
disable-all: true
enable:
- bodyclose
- deadcode
- dogsled
- errcheck
- funlen
- gocognit
- goconst
- gocritic
- goimports
- golint
- goprintffuncname
- gosimple
- govet
- ineffassign
- lll
- misspell
- nakedret
- staticcheck
- nestif
- structcheck
- typecheck
- unconvert
- unparam
- varcheck
- whitespace
fast: false
4 changes: 0 additions & 4 deletions api_captions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ var captionStructs = []Subtitle{
},
}

var captionRequestJSON = `{
"default": true
}`

func TestCaptions_Get(t *testing.T) {
setup()
defer teardown()
Expand Down
6 changes: 0 additions & 6 deletions api_live_streams_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,6 @@ var liveStructs = []LiveStream{
},
}

var liveRequestJSON = `{
"name": "Test live",
"record": true,
"playerId": "pl4f4ferf5erfr5zed4fsdd"
}`

var liveStreamCreatePayload = LiveStreamCreatePayload{
Name: "Test live",
Record: PtrBool(true),
Expand Down
17 changes: 0 additions & 17 deletions api_player_themes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,23 +100,6 @@ var playerStructs = []Player{
},
}

var playerRequestJSON = `{
"text": PtrString("rgba(255, 255, 255, 0.95)"),
"link": PtrString("rgba(255, 0, 0, 0.95)"),
"linkHover": PtrString("rgba(255, 255, 255, 0.75)"),
"trackPlayed": PtrString("rgba(255, 255, 255, 0.95)"),
"trackUnplayed": PtrString("rgba(255, 255, 255, 0.1)"),
"trackBackground": PtrString("rgba(0, 0, 0, 0)"),
"backgroundTop": PtrString("rgba(72, 4, 45, 1)"),
"backgroundBottom": PtrString("rgba(94, 95, 89, 1)"),
"backgroundText": PtrString("rgba(255, 255, 255, 0.95)"),
"enableApi": false,
"enableControls": true,
"forceAutoplay": false,
"hideTitle": false,
"forceLoop": false
}`

var playerCreationPayload = PlayerCreationPayload{
Text: PtrString("rgba(255, 255, 255, 0.95)"),
Link: PtrString("rgba(255, 0, 0, 0.95)"),
Expand Down
31 changes: 1 addition & 30 deletions api_videos_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"os"
"reflect"
"testing"
"time"
)

var videoJSONResponses = []string{`{
Expand Down Expand Up @@ -79,11 +78,6 @@ var videoJSONResponses = []string{`{
}`,
}

func getTime(timStr string) time.Time {
parsed, _ := time.Parse("2006-01-02T15:04:05.000Z", timStr)
return parsed
}

var videoStructs = []Video{
{
VideoId: PtrString("vi4k0jvEUuaTdRAEjQ4Jfagz"),
Expand Down Expand Up @@ -146,29 +140,6 @@ var videoStructs = []Video{
},
}

var videoRequestJSON = `{
"title": "Maths video",
"description": "An amazing video explaining the string theory",
"public": true,
"mp4Support":true,
"playerId": "pl45KFKdlddgk654dspkze",
"tags": [
"maths",
"string theory",
"video"
],
"metadata": [
{
"key": "Author",
"value": "John Doe"
},
{
"key": "Format",
"value": "Tutorial"
}
]
}`

var videoCreatePayload = VideoCreatePayload{
Title: "Maths video",
Description: PtrString("An amazing video explaining the string theory"),
Expand Down Expand Up @@ -590,7 +561,7 @@ func TestVideos_ChunkedUpload(t *testing.T) {

filesize := int64(8 * 1024 * 1024)
chunksize := int64(2 * 1024 * 1024)
nbRequests := (filesize / chunksize)
nbRequests := filesize / chunksize
file := createTempFile("test.video", filesize)
defer os.Remove(file.Name())

Expand Down
57 changes: 26 additions & 31 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
type Client struct {
BaseURL *url.URL
APIKey string
httpClient *Doer
httpClient Doer
chunkSize int64
Token *Token

Expand Down Expand Up @@ -73,48 +73,48 @@ type Doer interface {
Do(*http.Request) (*http.Response, error)
}

type clientBuilder struct {
type Builder struct {
apiKey string
baseURL string
uploadChunkSize int64
httpClient *Doer
httpClient Doer
}

func (cb *clientBuilder) BaseUrl(url string) *clientBuilder {
func (cb *Builder) BaseURL(url string) *Builder {
cb.baseURL = url
return cb
}

func (cb *clientBuilder) ApiKey(key string) *clientBuilder {
func (cb *Builder) APIKey(key string) *Builder {
cb.apiKey = key
return cb
}

func (cb *clientBuilder) UploadChunkSize(size int64) *clientBuilder {
func (cb *Builder) UploadChunkSize(size int64) *Builder {
cb.uploadChunkSize = size
return cb
}

func (cb *clientBuilder) HttpClient(httpClient *Doer) *clientBuilder {
func (cb *Builder) HTTPClient(httpClient Doer) *Builder {
cb.httpClient = httpClient
return cb
}

// ClientBuilder returns a new api.video API client builder for production
func ClientBuilder(apiKey string) *clientBuilder {
return &clientBuilder{
func ClientBuilder(apiKey string) *Builder {
return &Builder{
baseURL: defaultBaseURL,
uploadChunkSize: defaultChunkSize,
apiKey: apiKey,
}
}

// SandboxClientBuilder returns a new api.video API client builder for sandbox environment
func SandboxClientBuilder(apiKey string) *clientBuilder {
return ClientBuilder(apiKey).BaseUrl(defaultSandboxBaseURL)
func SandboxClientBuilder(apiKey string) *Builder {
return ClientBuilder(apiKey).BaseURL(defaultSandboxBaseURL)
}

func (cb *clientBuilder) Build() *Client {
func (cb *Builder) Build() *Client {

baseURL, _ := url.Parse(cb.baseURL)

Expand All @@ -123,13 +123,13 @@ func (cb *clientBuilder) Build() *Client {
if cb.httpClient == nil {
httpClient = http.DefaultClient
} else {
httpClient = *cb.httpClient
httpClient = cb.httpClient
}

c := &Client{
BaseURL: baseURL,
APIKey: cb.apiKey,
httpClient: &httpClient,
httpClient: httpClient,
chunkSize: cb.uploadChunkSize,
}

Expand All @@ -146,7 +146,7 @@ func (cb *clientBuilder) Build() *Client {
return c
}

//ChunkSize changes chunk size for video upload, by default its 128MB
// ChunkSize changes chunk size for video upload, by default its 128MB
func (c *Client) ChunkSize(size int64) {
c.chunkSize = size
}
Expand Down Expand Up @@ -236,12 +236,10 @@ func (c *Client) prepareRangeRequests(
return nil, err
}

if formParams != nil {
for key, val := range formParams {
err = writer.WriteField(key, val)
if err != nil {
return nil, err
}
for key, val := range formParams {
err = writer.WriteField(key, val)
if err != nil {
return nil, err
}
}

Expand Down Expand Up @@ -307,12 +305,10 @@ func (c *Client) prepareUploadRequest(
return nil, err
}

if formParams != nil {
for key, val := range formParams {
err = writer.WriteField(key, val)
if err != nil {
return nil, err
}
for key, val := range formParams {
err = writer.WriteField(key, val)
if err != nil {
return nil, err
}
}

Expand All @@ -332,8 +328,8 @@ func (c *Client) prepareUploadRequest(
}

func (c *Client) do(req *http.Request, v interface{}) (*http.Response, error) {
cl := *c.httpClient
resp, err := cl.Do(req)
resp, err := c.httpClient.Do(req)

if err != nil {
return nil, err
}
Expand Down Expand Up @@ -381,8 +377,7 @@ func (c *Client) auth(req *http.Request) (*http.Request, error) {
req.Header.Set("Content-Type", "application/json")
req.Header.Set("User-Agent", "api.video SDK (go; v:1.0)")

cl := *c.httpClient
resp, err := cl.Do(req)
resp, err := c.httpClient.Do(req)

if err != nil {
return nil, err
Expand Down

0 comments on commit 2d886f2

Please sign in to comment.