~blu/artemis

bb3c3bc89cad6f494e0da416866bd4006c426993 — Bryant Conquest 1 year, 4 months ago 6be64eb + 34b9b66
Merge branch 'main' into feature/dockerization
4 files changed, 53 insertions(+), 4 deletions(-)

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

import (
	"os"

	"github.com/BurntSushi/toml"
)

// PREFERS to use environmental variables
// ARTEMIS_APP_ID & ARTEMIS_KEY_SECRET
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)
	if err != nil {
		return &config, err
	}

	config.B2.AppID = os.Getenv("ARTEMIS_APP_ID")
	config.B2.KeySecret = os.Getenv("ARTEMIS_KEY_SECRET")

	if config.Cache.Pattern == "" {
		config.Cache.Pattern = "artemis-*"
	}
	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)
	}