Skip to content

Commit

Permalink
initial commit of WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
ramin committed Mar 18, 2024
0 parents commit 5c5abf4
Show file tree
Hide file tree
Showing 19 changed files with 969 additions and 0 deletions.
64 changes: 64 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: build and test

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
lint:
name: Lint
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- uses: actions/setup-go@v5
with:
go-version-file: go.mod

- name: golangci-lint
uses: golangci/golangci-lint-action@v4
with:
args: --timeout 8m --verbose
version: v1.56
skip-pkg-cache: true
skip-build-cache: true

go_mod_tidy_check:
name: Mod Tidy Check
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- uses: actions/setup-go@v5
with:
go-version-file: go.mod

- run: go mod tidy

- name: check for diff
run: git diff --exit-code

test:
needs: [lint, go_mod_tidy_check]
name: Unit tests
strategy:
matrix:
os: [ubuntu-latest, macos-latest]

runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v4

- uses: actions/setup-go@v5
with:
go-version-file: go.mod

- name: Run tests
run: go test -coverprofile=coverage.txt -covermode=atomic ./...
20 changes: 20 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
bin

# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
# vendor/

# Go workspace file
go.work
54 changes: 54 additions & 0 deletions .golang-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
run:
timeout: 5m

linters:
enable:
- bodyclose
- dogsled
- dupl
- errcheck
- goconst
- gocritic
- gofmt
- goimports
- revive
- gosec
- gosimple
- govet
- ineffassign
- lll
- misspell
- nakedret
- prealloc
- exportloopref
- staticcheck
- stylecheck
- typecheck
- unconvert
- unused
- whitespace
- wsl
- nolintlint
- asciicheck

issues:
exclude-rules:
- path: _test\.go
linters:
- gosec
- linters:
- lll
source: "https://"
max-same-issues: 50

linters-settings:
dogsled:
max-blank-identifiers: 3
golint:
min-confidence: 0
maligned:
suggest-new: true
misspell:
locale: US
dupl:
threshold: 200
Empty file added README.md
Empty file.
72 changes: 72 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package eclair

import (
"net/http"

"github.com/edobtc/go-eclair/httpclient"
)

type Client struct {
settings *Settings
BaseURL string
HTTPClient *http.Client

Debug bool
}

func NewClient() *Client {
return &Client{
settings: NewDefaultSettings(),
HTTPClient: httpclient.New(),
}
}

func NewClientFromSettings(settings *Settings) *Client {
return &Client{
settings: settings,
HTTPClient: httpclient.New(),
}
}

func (c *Client) _settings() *Settings {
if c.settings == nil {
c.settings = NewDefaultSettings()
}

if c.settings.Credentials == nil {
c.settings.Credentials = &Credentials{}
}

return c.settings
}

func (c *Client) WithBaseURL(baseURL string) *Client {
c.BaseURL = baseURL
return c
}

func (c *Client) WithCredentials(creds *Credentials) *Client {
c._settings().Credentials = creds
return c
}

func (c *Client) WithUser(user string) *Client {
c._settings().Credentials.User = user
return c
}

func (c *Client) WithPassword(password string) *Client {

c.settings.Credentials.Password = password
return c
}

func (c *Client) WithHTTPClient(client *http.Client) *Client {
c.HTTPClient = client
return c
}

func (c *Client) WithDebug(debug bool) *Client {
c.Debug = debug
return c
}
59 changes: 59 additions & 0 deletions client_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package eclair

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestNewClient(t *testing.T) {
client := NewClient()
assert.NotNil(t, client)
assert.NotNil(t, client.settings)
assert.NotNil(t, client.HTTPClient)
}

func TestNewClientFromSettings(t *testing.T) {
settings := NewDefaultSettings()
client := NewClientFromSettings(settings)
assert.NotNil(t, client)
assert.Equal(t, settings, client.settings)
assert.NotNil(t, client.HTTPClient)
}

func TestClient_settings(t *testing.T) {
client := NewClient()
assert.NotNil(t, client._settings())
assert.Equal(t, client.settings, client._settings())
}

func TestClient_WithBaseURL(t *testing.T) {
client := NewClient()
baseURL := "http://localhost:8080"
client.WithBaseURL(baseURL)
assert.Equal(t, baseURL, client.BaseURL)
}

func TestClient_WithCredentials(t *testing.T) {
client := NewClient()
creds := &Credentials{
User: "user",
Password: "password",
}
client.WithCredentials(creds)
assert.Equal(t, creds, client.settings.Credentials)
}

func TestClient_WithUser(t *testing.T) {
client := NewClient()
user := "user"
client.WithUser(user)
assert.Equal(t, user, client.settings.Credentials.User)
}

func TestClient_WithPassword(t *testing.T) {
client := NewClient()
password := "password"
client.WithPassword(password)
assert.Equal(t, password, client.settings.Credentials.Password)
}
Loading

0 comments on commit 5c5abf4

Please sign in to comment.