~blu/artemis

a85d1ff89f6ecee1d5ad85f391d1753002ab7737 — Bryant Conquest 1 year, 5 months ago 74e046a
start work on config
4 files changed, 39 insertions(+), 4 deletions(-)

A config/config.go
M go.mod
A go.sum
M main.go
A config/config.go => config/config.go +26 -0
@@ 0,0 1,26 @@
package config

import (
	"github.com/BurntSushi/toml"
)

type b2 struct {
	AppID     string `toml:"app_id"`
	KeySecret string `toml:"key_secret"`
}

type cache struct {
	Pattern string `toml:"pattern"`
}

type Config struct {
	B2    *b2    `toml:"b2"`
	Cache *cache `toml:"cache"`
}

func Load(path string) (*Config, error) {
	var config Config

	_, err := toml.DecodeFile(path, &config)
	return &config, err
}

M go.mod => go.mod +2 -0
@@ 1,3 1,5 @@
module blu.moe/artemis

go 1.19

require github.com/BurntSushi/toml v1.2.1 // indirect

A go.sum => go.sum +2 -0
@@ 0,0 1,2 @@
github.com/BurntSushi/toml v1.2.1 h1:9F2/+DoOYIOksmaJFPw1tGFy1eDnIJXg+UHjuD8lTak=
github.com/BurntSushi/toml v1.2.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=

M main.go => main.go +9 -4
@@ 6,12 6,12 @@ import (
	"fmt"
	"log"
	"net/http"
	"os"
	"strings"
	"sync"

	"blu.moe/artemis/b2"
	"blu.moe/artemis/cache"
	"blu.moe/artemis/config"
)

var (


@@ 91,11 91,16 @@ func Logger(next http.Handler) http.Handler {
}

func main() {
	cfg, err := config.Load("../artemis.toml")
	if err != nil {
		log.Fatal(err)
	}

	b2Client, err := b2.NewClient().
		WithClient(10).
		WithAuthorization(
			os.Getenv("ARTEMIS_APP_ID"),
			os.Getenv("ARTEMIS_KEY_SECRET"),
			cfg.B2.AppID,
			cfg.B2.KeySecret,
		)
	if err != nil {
		log.Fatal(err)


@@ 103,7 108,7 @@ func main() {

	cache, err := cache.NewCache().
		WithFileClient(b2Client).
		WithDirectory("artemis-*")
		WithDirectory(cfg.Cache.Pattern)
	if err != nil {
		log.Fatal(err)
	}