Skip to content

Commit

Permalink
split config reader from model to different files
Browse files Browse the repository at this point in the history
  • Loading branch information
mesuutt committed Jun 25, 2023
1 parent e9d29f3 commit be87afc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 21 deletions.
21 changes: 0 additions & 21 deletions internal/config/config.go → internal/config/model.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
package config

import (
"fmt"
"os"

"github.com/pelletier/go-toml/v2"
)

type Config struct {
Commit CommitConfig
Overwrites map[string]map[string]string
Expand All @@ -17,20 +10,6 @@ type CommitConfig struct {
Template string
}

func ReadConfig(path string) (*Config, error) {
bytes, err := os.ReadFile(path)
if err != nil {
return nil, err
}

var conf Config
if err := toml.Unmarshal(bytes, &conf); err != nil {
return nil, fmt.Errorf("config file parse failed: %s, error: %w", path, err)
}

return &conf, nil
}

func Default() *Config {
return &Config{
Commit: CommitConfig{
Expand Down
22 changes: 22 additions & 0 deletions internal/config/reader.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package config

import (
"fmt"
"os"

"github.com/pelletier/go-toml/v2"
)

func ReadConfig(path string) (*Config, error) {
bytes, err := os.ReadFile(path)
if err != nil {
return nil, err
}

var conf Config
if err := toml.Unmarshal(bytes, &conf); err != nil {
return nil, fmt.Errorf("config file parse failed: %s, error: %w", path, err)
}

return &conf, nil
}

0 comments on commit be87afc

Please sign in to comment.