Skip to content

Commit

Permalink
Switch to yml-based config.
Browse files Browse the repository at this point in the history
  • Loading branch information
samshadwell committed Nov 17, 2023
1 parent 18ac9e6 commit c81b6b4
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@
go.work

# Sensitive config
config.go
config.yml
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ This integration makes the bookkeeping easier. Our setup is:

## Configuration

Configuration is assumed to live in a `config.go` file at the root of the application. For security reasons, I don't
check this file into Git, but you can see the general structure in `config.go.example`. To use this yourself, first
Configuration is assumed to live in a `config.yml` file at the root of the application. For security reasons, I don't
check this file into Git, but you can see the general structure in `config.yml.example`. To use this yourself, first
run:

```shell
cp config.go.example config.go
cp config.yml.example config.yml
```

Then fill in the values in `config.go` with your own values.
Then fill in the values in `config.yml` with your own values.
31 changes: 31 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package main

import (
"fmt"
"os"

"gopkg.in/yaml.v2"
)

type Config struct {
YnabToken string `yaml:"ynabToken"`
BudgetId string `yaml:"budgetId"`
}

func NewConfig() *Config {
f, err := os.Open("config.yml")
if err != nil {
fmt.Fprintf(os.Stderr, "Error opening config file. Did you create a config.yml? %v\n", err)
os.Exit(1)
}
defer f.Close()

var cfg Config
decoder := yaml.NewDecoder(f)
err = decoder.Decode(&cfg)
if err != nil {
fmt.Fprintf(os.Stderr, "Error decoding config file. Make sure it has the correct format. See config.yml.example for an example %v\n", err)
}

return &cfg
}
15 changes: 0 additions & 15 deletions config.go.example

This file was deleted.

3 changes: 3 additions & 0 deletions config.yml.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
ynabToken: "xxx"
budgetId: "yyy"
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@ module github.com/samshadwell/split-ynab

go 1.21

require github.com/brunomvsouza/ynab.go v1.4.0 // indirect
require (
github.com/brunomvsouza/ynab.go v1.4.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
github.com/brunomvsouza/ynab.go v1.4.0 h1:j32NsAq74sxWtfi16cFrn/aj2K8sZpaXPlcJiB9bwRk=
github.com/brunomvsouza/ynab.go v1.4.0/go.mod h1:u5zDi6NY53RIqel+hzVodPr0CuZ0ZONbf03cex+kods=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=

0 comments on commit c81b6b4

Please sign in to comment.