Skip to content

Commit

Permalink
Fix codacy
Browse files Browse the repository at this point in the history
  • Loading branch information
murat committed May 3, 2022
1 parent 4cbc554 commit f143e2a
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
![Lint](https://github.com/murat/dicterm/actions/workflows/lint.yml/badge.svg)
![Tests](https://github.com/murat/dicterm/actions/workflows/test.yml/badge.svg)
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/295007f859ca44b5b1a9418bb5685d40)](https://www.codacy.com/gh/murat/dicterm/dashboard?utm_source=github.com&utm_medium=referral&utm_content=murat/dicterm&utm_campaign=Badge_Grade)
[![Codacy Badge](https://app.codacy.com/project/badge/Coverage/295007f859ca44b5b1a9418bb5685d40)](https://www.codacy.com/gh/murat/dicterm/dashboard?utm_source=github.com&utm_medium=referral&utm_content=murat/dicterm&utm_campaign=Badge_Coverage)

dicterm is a cli interface for merriem webster dictionary.

Expand Down Expand Up @@ -65,5 +66,5 @@ stems:
## Todo
- [x] store key in a dotfile
- [ ] use a beatiful tui
- [X] store key in a dotfile
- [ ] use a beatiful tui
2 changes: 2 additions & 0 deletions internal/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ import (
"net/http"
)

// Handler is the handler for the API.
type Handler struct {
Client *http.Client
BaseURL string
Key string
}

const (
// BaseURL is the base URL for the API.
BaseURL = "https://www.dictionaryapi.com/api/v3/references/collegiate/json"
)

Expand Down
4 changes: 4 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ import (
"os"
)

// IConfig is interface for config file
type IConfig interface {
Read() (*string, error)
Write(string) error
}

// Config is configuration file
type Config struct {
File *os.File
}
Expand All @@ -35,6 +37,7 @@ func New(path string) (*Config, error) {
return &Config{file}, nil
}

// Read reads key from config file
func (cfg *Config) Read() (*string, error) {
buf := make([]byte, 1024)
n, err := cfg.File.Read(buf)
Expand All @@ -50,6 +53,7 @@ func (cfg *Config) Read() (*string, error) {
return &key, nil
}

// Write writes key to config file
func (cfg *Config) Write(key string) error {
_, err := cfg.File.Write([]byte(key))
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions internal/config/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ package config

import "errors"

// ErrEmptyFile is error for empty config file
var ErrEmptyFile = errors.New("file is empty")

0 comments on commit f143e2a

Please sign in to comment.