Compare commits

...

10 Commits

Author SHA1 Message Date
c551806f56 Merge pull request 'chore(deps): update goreleaser/goreleaser-action action to v6.4.0' (#9) from renovate/actions into master
All checks were successful
Run Golang tests / Run unit tests (stable, ubuntu-latest-amd64) (push) Successful in 6s
Lint Markdown files / Run markdown linter (push) Successful in 4s
Lint Golang files / Run golang CI linter (stable, ubuntu-latest-amd64) (push) Successful in 49s
Lint Golang files / Run golang CI linter (stable, ubuntu-latest-arm64) (push) Successful in 30s
Run Golang tests / Run unit tests (stable, ubuntu-latest-arm64) (push) Successful in 20s
2025-08-14 16:10:44 +00:00
ff32c63ec0 chore(deps): update goreleaser/goreleaser-action action to v6.4.0
All checks were successful
Lint Golang files / Run golang CI linter (stable, ubuntu-latest-amd64) (push) Successful in 9s
Run Golang tests / Run unit tests (stable, ubuntu-latest-amd64) (push) Successful in 6s
Lint Golang files / Run golang CI linter (stable, ubuntu-latest-amd64) (pull_request) Successful in 8s
Run Golang tests / Run unit tests (stable, ubuntu-latest-amd64) (pull_request) Successful in 5s
Lint Markdown files / Run markdown linter (pull_request) Successful in 4s
Lint Golang files / Run golang CI linter (stable, ubuntu-latest-arm64) (push) Successful in 27s
Run Golang tests / Run unit tests (stable, ubuntu-latest-arm64) (push) Successful in 19s
Lint Golang files / Run golang CI linter (stable, ubuntu-latest-arm64) (pull_request) Successful in 27s
Run Golang tests / Run unit tests (stable, ubuntu-latest-arm64) (pull_request) Successful in 20s
2025-08-14 16:04:39 +00:00
3d4e5d0e15 Merge pull request 'chore(deps): update dependency golangci/golangci-lint to v2.4.0' (#8) from renovate/golangci-golangci-lint-2.x into master
All checks were successful
Run Golang tests / Run unit tests (stable, ubuntu-latest-amd64) (push) Successful in 7s
Lint Markdown files / Run markdown linter (push) Successful in 4s
Lint Golang files / Run golang CI linter (stable, ubuntu-latest-amd64) (push) Successful in 1m38s
Lint Golang files / Run golang CI linter (stable, ubuntu-latest-arm64) (push) Successful in 28s
Run Golang tests / Run unit tests (stable, ubuntu-latest-arm64) (push) Successful in 19s
2025-08-14 01:21:19 +00:00
742a00d91d chore(deps): update dependency golangci/golangci-lint to v2.4.0
All checks were successful
Lint Golang files / Run golang CI linter (stable, ubuntu-latest-amd64) (push) Successful in 26s
Lint Golang files / Run golang CI linter (stable, ubuntu-latest-amd64) (pull_request) Successful in 8s
Run Golang tests / Run unit tests (stable, ubuntu-latest-amd64) (pull_request) Successful in 13s
Lint Markdown files / Run markdown linter (pull_request) Successful in 4s
Run Golang tests / Run unit tests (stable, ubuntu-latest-amd64) (push) Successful in 1m42s
Lint Golang files / Run golang CI linter (stable, ubuntu-latest-arm64) (push) Successful in 1m28s
Run Golang tests / Run unit tests (stable, ubuntu-latest-arm64) (push) Successful in 49s
Lint Golang files / Run golang CI linter (stable, ubuntu-latest-arm64) (pull_request) Successful in 30s
Run Golang tests / Run unit tests (stable, ubuntu-latest-arm64) (pull_request) Successful in 21s
2025-08-14 01:05:32 +00:00
7425cfe2d0 Merge pull request 'chore(deps): update dependency golangci/golangci-lint to v2.3.1' (#7) from renovate/golangci-golangci-lint-2.x into master
All checks were successful
Lint Golang files / Run golang CI linter (stable, ubuntu-latest-amd64) (push) Successful in 12s
Lint Markdown files / Run markdown linter (push) Successful in 4s
Run Golang tests / Run unit tests (stable, ubuntu-latest-amd64) (push) Successful in 36s
Run Golang tests / Run unit tests (stable, ubuntu-latest-arm64) (push) Successful in 20s
Lint Golang files / Run golang CI linter (stable, ubuntu-latest-arm64) (push) Successful in 41s
2025-08-12 16:20:37 +00:00
ccd0d62503 chore(deps): update dependency golangci/golangci-lint to v2.3.1
All checks were successful
Lint Golang files / Run golang CI linter (stable, ubuntu-latest-amd64) (push) Successful in 12s
Run Golang tests / Run unit tests (stable, ubuntu-latest-amd64) (push) Successful in 6s
Lint Golang files / Run golang CI linter (stable, ubuntu-latest-amd64) (pull_request) Successful in 11s
Run Golang tests / Run unit tests (stable, ubuntu-latest-amd64) (pull_request) Successful in 5s
Lint Markdown files / Run markdown linter (pull_request) Successful in 3s
Lint Golang files / Run golang CI linter (stable, ubuntu-latest-arm64) (push) Successful in 41s
Run Golang tests / Run unit tests (stable, ubuntu-latest-arm64) (push) Successful in 22s
Lint Golang files / Run golang CI linter (stable, ubuntu-latest-arm64) (pull_request) Successful in 41s
Run Golang tests / Run unit tests (stable, ubuntu-latest-arm64) (pull_request) Successful in 20s
2025-08-12 13:03:42 +00:00
0bfc39536d Merge pull request 'chore(deps): update docker/login-action action to v3.5.0' (#5) from renovate/actions into master
All checks were successful
Lint Golang files / Run golang CI linter (stable, ubuntu-latest-amd64) (push) Successful in 12s
Lint Markdown files / Run markdown linter (push) Successful in 4s
Lint Golang files / Run golang CI linter (stable, ubuntu-latest-arm64) (push) Successful in 39s
Run Golang tests / Run unit tests (stable, ubuntu-latest-amd64) (push) Successful in 39s
Run Golang tests / Run unit tests (stable, ubuntu-latest-arm64) (push) Successful in 19s
2025-08-12 12:15:06 +00:00
32bc80cc49 chore(deps): update actions/checkout action to v4.3.0
All checks were successful
Lint Golang files / Run golang CI linter (stable, ubuntu-latest-amd64) (push) Successful in 11s
Run Golang tests / Run unit tests (stable, ubuntu-latest-amd64) (push) Successful in 5s
Lint Golang files / Run golang CI linter (stable, ubuntu-latest-amd64) (pull_request) Successful in 12s
Run Golang tests / Run unit tests (stable, ubuntu-latest-amd64) (pull_request) Successful in 5s
Lint Markdown files / Run markdown linter (pull_request) Successful in 4s
Lint Golang files / Run golang CI linter (stable, ubuntu-latest-arm64) (push) Successful in 41s
Run Golang tests / Run unit tests (stable, ubuntu-latest-arm64) (push) Successful in 18s
Lint Golang files / Run golang CI linter (stable, ubuntu-latest-arm64) (pull_request) Successful in 40s
Run Golang tests / Run unit tests (stable, ubuntu-latest-arm64) (pull_request) Successful in 21s
2025-08-12 12:10:55 +00:00
b0c90c4cb3 fix(lint): be compliant with golangci-lint
All checks were successful
Lint Golang files / Run golang CI linter (stable, ubuntu-latest-amd64) (push) Successful in 20s
Lint Markdown files / Run markdown linter (push) Successful in 3s
Run Golang tests / Run unit tests (stable, ubuntu-latest-amd64) (push) Successful in 35s
Lint Golang files / Run golang CI linter (stable, ubuntu-latest-arm64) (push) Successful in 1m3s
Run Golang tests / Run unit tests (stable, ubuntu-latest-arm64) (push) Successful in 19s
2025-08-12 13:53:32 +02:00
b4dcb26b45 fix(ci): rename workflows; add golang ci lint
Some checks failed
Lint Markdown files / Run markdown linter (push) Successful in 4s
Lint Golang files / Run golang CI linter (stable, ubuntu-latest-amd64) (push) Failing after 15s
Run Golang tests / Run unit tests (stable, ubuntu-latest-amd64) (push) Successful in 27s
Lint Golang files / Run golang CI linter (stable, ubuntu-latest-arm64) (push) Failing after 57s
Run Golang tests / Run unit tests (stable, ubuntu-latest-arm64) (push) Successful in 17s
2025-08-12 09:25:53 +02:00
13 changed files with 227 additions and 56 deletions

1
.dockerignore Normal file
View File

@ -0,0 +1 @@
app

View File

@ -1,12 +1,13 @@
# Editor configuration, see http://editorconfig.org
root = true root = true
[*] [*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8 charset = utf-8
trim_trailing_whitespace = true end_of_line = lf
indent_size = 2
indent_style = space
insert_final_newline = false insert_final_newline = false
trim_trailing_whitespace = true
[Makefile] [{Makefile,*.go}]
indent_style = tab indent_style = tab

1
.gitattributes vendored
View File

@ -1 +0,0 @@
Makefile eol=lf

View File

@ -1,4 +1,4 @@
name: Golang CI lint name: "Lint Golang files"
on: on:
pull_request: pull_request:
@ -6,22 +6,24 @@ on:
push: push:
branches: [ '**' ] branches: [ '**' ]
tags-ignore: [ '**' ] tags-ignore: [ '**' ]
workflow_dispatch: {}
permissions: permissions:
contents: read contents: read
jobs: jobs:
golangci: golangci:
name: "Run golang CI linter"
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
strategy: strategy:
matrix: matrix:
go: [ stable ] go: [ stable ]
os: [ ubuntu-latest-amd64, ubuntu-latest-arm64 ] os: [ ubuntu-latest-amd64, ubuntu-latest-arm64 ]
steps: steps:
- uses: actions/checkout@v4.2.2 - uses: actions/checkout@v4.3.0
- uses: actions/setup-go@v5.5.0 - uses: actions/setup-go@v5.5.0
with: with:
go-version: ${{ matrix.go }} go-version: ${{ matrix.go }}
- uses: golangci/golangci-lint-action@v8.0.0 - uses: golangci/golangci-lint-action@v8.0.0
with: with:
version: v2.1 version: v2.4.0 # renovate: datasource=github-releases depName=golangci/golangci-lint

View File

@ -1,4 +1,4 @@
name: Golang Tests name: "Run Golang tests"
on: on:
pull_request: pull_request:
@ -6,16 +6,34 @@ on:
push: push:
branches: [ '**' ] branches: [ '**' ]
tags-ignore: [ '**' ] tags-ignore: [ '**' ]
workflow_dispatch: {}
jobs: jobs:
unittest: # integration-test:
# name: "Run integration tests"
# runs-on: ${{ matrix.os }}
# strategy:
# matrix:
# go: [ stable ]
# os: [ ubuntu-latest-amd64, ubuntu-latest-arm64 ]
# steps:
# - uses: actions/checkout@v4.3.0
# - uses: actions/setup-go@v5.5.0
# with:
# go-version: ${{ matrix.go }}
# - env:
# GOPROXY: ${{ vars.GOPROXY }}
# run: make test/integration
unit-test:
name: "Run unit tests"
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
strategy: strategy:
matrix: matrix:
go: [ stable ] go: [ stable ]
os: [ ubuntu-latest-amd64, ubuntu-latest-arm64 ] os: [ ubuntu-latest-amd64, ubuntu-latest-arm64 ]
steps: steps:
- uses: actions/checkout@v4.2.2 - uses: actions/checkout@v4.3.0
- uses: actions/setup-go@v5.5.0 - uses: actions/setup-go@v5.5.0
with: with:
go-version: ${{ matrix.go }} go-version: ${{ matrix.go }}

View File

@ -1,18 +1,19 @@
name: Lint Markdown files name: "Lint Markdown files"
on: on:
pull_request: pull_request:
types: [ "opened", "reopened", "synchronize" ] types: [ "opened", "reopened", "synchronize" ]
push: push:
branches: [ '**' ] branches: [ '*' ]
tags-ignore: [ '**' ] tags-ignore: [ '*' ]
workflow_dispatch: {}
jobs: jobs:
markdown-lint: markdown-lint:
runs-on: name: "Run markdown linter"
- ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v4.2.2 - uses: actions/checkout@v4.3.0
- uses: DavidAnson/markdownlint-cli2-action@v20.0.0 - uses: DavidAnson/markdownlint-cli2-action@v20.0.0
with: with:
globs: '**/*.md' globs: '**/*.md'

View File

@ -1,4 +1,4 @@
name: Release name: "Release"
on: on:
push: push:
@ -9,15 +9,15 @@ permissions:
jobs: jobs:
release: release:
runs-on: name: "Release application"
- ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v4.2.2 - uses: actions/checkout@v4.3.0
- uses: docker/setup-qemu-action@v3.6.0 - uses: docker/setup-qemu-action@v3.6.0
- uses: actions/setup-go@v5.5.0 - uses: actions/setup-go@v5.5.0
with: with:
go-version: stable go-version: stable
- uses: docker/login-action@v3.4.0 - uses: docker/login-action@v3.5.0
with: with:
registry: git.cryptic.systems registry: git.cryptic.systems
username: ${{ github.repository_owner }} username: ${{ github.repository_owner }}
@ -26,9 +26,9 @@ jobs:
GITEA_TOKEN: ${{ secrets.GIT_CRYPTIC_SYSTEMS_PACKAGE_REGISTRY_TOKEN }} GITEA_TOKEN: ${{ secrets.GIT_CRYPTIC_SYSTEMS_PACKAGE_REGISTRY_TOKEN }}
GONOSUMDB: ${{ vars.GONOSUMDB }} GONOSUMDB: ${{ vars.GONOSUMDB }}
GOPROXY: ${{ vars.GOPROXY }} GOPROXY: ${{ vars.GOPROXY }}
uses: goreleaser/goreleaser-action@v6.3.0 uses: goreleaser/goreleaser-action@v6.4.0
with: with:
version: "~> v2" version: v2.11.2 # renovate: datasource=github-releases depName=goreleaser/goreleaser
args: release --clean args: release --clean
sync-to-hub-docker-io: sync-to-hub-docker-io:

View File

@ -11,7 +11,7 @@ jobs:
runs-on: runs-on:
- ubuntu-latest - ubuntu-latest
steps: steps:
- uses: actions/checkout@v4.2.2 - uses: actions/checkout@v4.3.0
- uses: peter-evans/dockerhub-description@v4.0.2 - uses: peter-evans/dockerhub-description@v4.0.2
with: with:
username: ${{ secrets.DOCKER_IO_USERNAME }} username: ${{ secrets.DOCKER_IO_USERNAME }}

13
.golangci.yaml Normal file
View File

@ -0,0 +1,13 @@
version: "2"
linters:
default: standard
enable:
- errname
- gosec
exclusions:
rules: []
warn-unused: true
run:
tests: true

136
.markdownlint.yaml Normal file
View File

@ -0,0 +1,136 @@
# markdownlint YAML configuration
# https://github.com/DavidAnson/markdownlint/blob/main/schema/.markdownlint.yaml
# Default state for all rules
default: true
# Path to configuration file to extend
extends: null
# MD003/heading-style/header-style - Heading style
MD003:
# Heading style
style: "atx"
# MD004/ul-style - Unordered list style
MD004:
style: "dash"
# MD007/ul-indent - Unordered list indentation
MD007:
# Spaces for indent
indent: 2
# Whether to indent the first level of the list
start_indented: false
# MD009/no-trailing-spaces - Trailing spaces
MD009:
# Spaces for line break
br_spaces: 2
# Allow spaces for empty lines in list items
list_item_empty_lines: false
# Include unnecessary breaks
strict: false
# MD010/no-hard-tabs - Hard tabs
MD010:
# Include code blocks
code_blocks: true
# MD012/no-multiple-blanks - Multiple consecutive blank lines
MD012:
# Consecutive blank lines
maximum: 1
# MD013/line-length - Line length
MD013:
# Number of characters
line_length: 120
# Number of characters for headings
heading_line_length: 120
# Number of characters for code blocks
code_block_line_length: 120
# Include code blocks
code_blocks: false
# Include tables
tables: false
# Include headings
headings: true
# Strict length checking
strict: false
# Stern length checking
stern: false
# MD022/blanks-around-headings/blanks-around-headers - Headings should be surrounded by blank lines
MD022:
# Blank lines above heading
lines_above: 1
# Blank lines below heading
lines_below: 1
# MD025/single-title/single-h1 - Multiple top-level headings in the same document
MD025:
# Heading level
level: 1
# RegExp for matching title in front matter
front_matter_title: "^\\s*title\\s*[:=]"
# MD026/no-trailing-punctuation - Trailing punctuation in heading
MD026:
# Punctuation characters
punctuation: ".,;:!。,;:!"
# MD029/ol-prefix - Ordered list item prefix
MD029:
# List style
style: "one_or_ordered"
# MD030/list-marker-space - Spaces after list markers
MD030:
# Spaces for single-line unordered list items
ul_single: 1
# Spaces for single-line ordered list items
ol_single: 1
# Spaces for multi-line unordered list items
ul_multi: 1
# Spaces for multi-line ordered list items
ol_multi: 1
# MD033/no-inline-html - Inline HTML
MD033:
# Allowed elements
allowed_elements: []
# MD035/hr-style - Horizontal rule style
MD035:
# Horizontal rule style
style: "---"
# MD036/no-emphasis-as-heading/no-emphasis-as-header - Emphasis used instead of a heading
MD036:
# Punctuation characters
punctuation: ".,;:!?。,;:!?"
# MD041/first-line-heading/first-line-h1 - First line in a file should be a top-level heading
MD041:
# Heading level
level: 1
# RegExp for matching title in front matter
front_matter_title: "^\\s*title\\s*[:=]"
# MD044/proper-names - Proper names should have the correct capitalization
MD044:
# List of proper names
names: []
# Include code blocks
code_blocks: false
# MD046/code-block-style - Code block style
MD046:
# Block style
style: "fenced"
# MD048/code-fence-style - Code fence style
MD048:
# Code fence syle
style: "backtick"

View File

@ -2,7 +2,6 @@ package cmd
import ( import (
"fmt" "fmt"
"io/ioutil"
"log" "log"
"os" "os"
@ -59,7 +58,8 @@ func runE(cmd *cobra.Command, args []string) error {
return fmt.Errorf("can not find file: %v", file) return fmt.Errorf("can not find file: %v", file)
} }
f, err := ioutil.ReadFile(file) // #nosec G304
f, err := os.ReadFile(file)
if err != nil { if err != nil {
return fmt.Errorf("can not read file %v: %v", file, err) return fmt.Errorf("can not read file %v: %v", file, err)
} }

View File

@ -3,11 +3,11 @@ package hub
import "errors" import "errors"
var ( var (
errorFailedToCreateRequest = errors.New("failed to create http request") errFailedToCreateRequest = errors.New("failed to create http request")
errorFailedToParseJSON = errors.New("failed to parse json") errFailedToParseJSON = errors.New("failed to parse json")
errorFailedToParseURL = errors.New("failed to parse url") errFailedToParseURL = errors.New("failed to parse url")
errorFailedToSendRequest = errors.New("failed to send http request") errFailedToSendRequest = errors.New("failed to send http request")
errorNoNamespaceDefined = errors.New("no Namespace defined") errNoNamespaceDefined = errors.New("no Namespace defined")
errorNoRepositoryDefined = errors.New("no Repository defined") errNoRepositoryDefined = errors.New("no Repository defined")
errorUnexpectedHTTPStatuscode = errors.New("unexpected HTTP-Statuscode") errUnexpectedHTTPStatuscode = errors.New("unexpected HTTP-Statuscode")
) )

View File

@ -25,22 +25,22 @@ type Hub struct {
func (h *Hub) GetRepository(namespace string, name string) (*types.Repository, error) { func (h *Hub) GetRepository(namespace string, name string) (*types.Repository, error) {
if len(namespace) <= 0 { if len(namespace) <= 0 {
return nil, errorNoNamespaceDefined return nil, errNoNamespaceDefined
} }
if len(name) <= 0 { if len(name) <= 0 {
return nil, errorNoRepositoryDefined return nil, errNoRepositoryDefined
} }
rawURL := fmt.Sprintf("%v/repositories/%v/%v", dockerHubAPI, namespace, name) rawURL := fmt.Sprintf("%v/repositories/%v/%v", dockerHubAPI, namespace, name)
url, err := url.Parse(rawURL) url, err := url.Parse(rawURL)
if err != nil { if err != nil {
return nil, fmt.Errorf("%v: %v", errorFailedToParseURL, err) return nil, fmt.Errorf("%v: %v", errFailedToParseURL, err)
} }
req, err := http.NewRequest(http.MethodGet, url.String(), nil) req, err := http.NewRequest(http.MethodGet, url.String(), nil)
if err != nil { if err != nil {
return nil, fmt.Errorf("%v: %v", errorFailedToCreateRequest, err) return nil, fmt.Errorf("%v: %v", errFailedToCreateRequest, err)
} }
if h.token == nil { if h.token == nil {
@ -54,18 +54,18 @@ func (h *Hub) GetRepository(namespace string, name string) (*types.Repository, e
resp, err := h.client.Do(req) resp, err := h.client.Do(req)
if err != nil { if err != nil {
return nil, fmt.Errorf("%v: %v", errorFailedToSendRequest, err) return nil, fmt.Errorf("%v: %v", errFailedToSendRequest, err)
} }
defer func() { _ = resp.Body.Close() }() defer func() { _ = resp.Body.Close() }()
if resp.StatusCode != http.StatusOK { if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("%v: expect %v, received %v", errorUnexpectedHTTPStatuscode, http.StatusOK, resp.StatusCode) return nil, fmt.Errorf("%v: expect %v, received %v", errUnexpectedHTTPStatuscode, http.StatusOK, resp.StatusCode)
} }
repository := new(types.Repository) repository := new(types.Repository)
jsonDecoder := json.NewDecoder(resp.Body) jsonDecoder := json.NewDecoder(resp.Body)
if err := jsonDecoder.Decode(repository); err != nil { if err := jsonDecoder.Decode(repository); err != nil {
return nil, fmt.Errorf("%v: %v", errorFailedToParseJSON, err) return nil, fmt.Errorf("%v: %v", errFailedToParseJSON, err)
} }
return repository, nil return repository, nil
@ -75,30 +75,30 @@ func (h *Hub) getToken() (*types.Token, error) {
loginBuffer := new(bytes.Buffer) loginBuffer := new(bytes.Buffer)
jsonEncoder := json.NewEncoder(loginBuffer) jsonEncoder := json.NewEncoder(loginBuffer)
if err := jsonEncoder.Encode(h.credentials); err != nil { if err := jsonEncoder.Encode(h.credentials); err != nil {
return nil, fmt.Errorf("%v: %v", errorFailedToParseJSON, err) return nil, fmt.Errorf("%v: %v", errFailedToParseJSON, err)
} }
rawURL := fmt.Sprintf("%v/users/login/", dockerHubAPI) rawURL := fmt.Sprintf("%v/users/login/", dockerHubAPI)
req, err := http.NewRequest(http.MethodPost, rawURL, loginBuffer) req, err := http.NewRequest(http.MethodPost, rawURL, loginBuffer)
if err != nil { if err != nil {
return nil, fmt.Errorf("%v: %v", errorFailedToCreateRequest, err) return nil, fmt.Errorf("%v: %v", errFailedToCreateRequest, err)
} }
req.Header.Add("Content-Type", "application/json") req.Header.Add("Content-Type", "application/json")
resp, err := h.client.Do(req) resp, err := h.client.Do(req)
if err != nil { if err != nil {
return nil, fmt.Errorf("%v: %v", errorFailedToCreateRequest, err) return nil, fmt.Errorf("%v: %v", errFailedToCreateRequest, err)
} }
defer func() { _ = resp.Body.Close() }() defer func() { _ = resp.Body.Close() }()
if resp.StatusCode != http.StatusOK { if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("%v: expect %v, received %v", errorUnexpectedHTTPStatuscode, http.StatusOK, resp.StatusCode) return nil, fmt.Errorf("%v: expect %v, received %v", errUnexpectedHTTPStatuscode, http.StatusOK, resp.StatusCode)
} }
token := new(types.Token) token := new(types.Token)
jsonDecoder := json.NewDecoder(resp.Body) jsonDecoder := json.NewDecoder(resp.Body)
if err := jsonDecoder.Decode(token); err != nil { if err := jsonDecoder.Decode(token); err != nil {
return nil, fmt.Errorf("%v: %v", errorFailedToParseJSON, err) return nil, fmt.Errorf("%v: %v", errFailedToParseJSON, err)
} }
return token, nil return token, nil
@ -108,11 +108,11 @@ func (h *Hub) getToken() (*types.Token, error) {
func (h *Hub) PatchRepository(repository *types.Repository) (*types.Repository, error) { func (h *Hub) PatchRepository(repository *types.Repository) (*types.Repository, error) {
if len(repository.Namespcace) <= 0 { if len(repository.Namespcace) <= 0 {
return nil, errorNoNamespaceDefined return nil, errNoNamespaceDefined
} }
if len(repository.Name) <= 0 { if len(repository.Name) <= 0 {
return nil, errorNoRepositoryDefined return nil, errNoRepositoryDefined
} }
if h.token == nil { if h.token == nil {
@ -127,7 +127,7 @@ func (h *Hub) PatchRepository(repository *types.Repository) (*types.Repository,
rawURL := fmt.Sprintf("%v/repositories/%v/%v", dockerHubAPI, repository.Namespcace, repository.Name) rawURL := fmt.Sprintf("%v/repositories/%v/%v", dockerHubAPI, repository.Namespcace, repository.Name)
patchURL, err := url.Parse(rawURL) patchURL, err := url.Parse(rawURL)
if err != nil { if err != nil {
return nil, fmt.Errorf("%v: %v", errorFailedToParseURL, err) return nil, fmt.Errorf("%v: %v", errFailedToParseURL, err)
} }
data := &url.Values{} data := &url.Values{}
@ -136,24 +136,24 @@ func (h *Hub) PatchRepository(repository *types.Repository) (*types.Repository,
req, err := http.NewRequest(http.MethodPatch, patchURL.String(), nil) req, err := http.NewRequest(http.MethodPatch, patchURL.String(), nil)
if err != nil { if err != nil {
return nil, fmt.Errorf("%v: %v", errorFailedToCreateRequest, err) return nil, fmt.Errorf("%v: %v", errFailedToCreateRequest, err)
} }
req.Header.Set("Authorization", fmt.Sprintf("JWT %v", h.token.Token)) req.Header.Set("Authorization", fmt.Sprintf("JWT %v", h.token.Token))
resp, err := h.client.Do(req) resp, err := h.client.Do(req)
if err != nil { if err != nil {
return nil, fmt.Errorf("%v: %v", errorFailedToCreateRequest, err) return nil, fmt.Errorf("%v: %v", errFailedToCreateRequest, err)
} }
defer func() { _ = resp.Body.Close() }() defer func() { _ = resp.Body.Close() }()
if resp.StatusCode != http.StatusOK { if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("%v: expect %v, received %v", errorUnexpectedHTTPStatuscode, http.StatusOK, resp.StatusCode) return nil, fmt.Errorf("%v: expect %v, received %v", errUnexpectedHTTPStatuscode, http.StatusOK, resp.StatusCode)
} }
patchedRepository := new(types.Repository) patchedRepository := new(types.Repository)
jsonDecoder := json.NewDecoder(resp.Body) jsonDecoder := json.NewDecoder(resp.Body)
if err := jsonDecoder.Decode(h.token); err != nil { if err := jsonDecoder.Decode(h.token); err != nil {
return nil, fmt.Errorf("%v: %v", errorFailedToParseJSON, err) return nil, fmt.Errorf("%v: %v", errFailedToParseJSON, err)
} }
return patchedRepository, nil return patchedRepository, nil