Skip to content

Commit

Permalink
refactor: cleanup/reabstract
Browse files Browse the repository at this point in the history
  • Loading branch information
abhijit-hota committed May 10, 2022
1 parent e039da4 commit be82d5a
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 138 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
*.db
tmp
tmp
temp
10 changes: 7 additions & 3 deletions api/bingo.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
DatabasePath = "../links.db"
ShouldSaveOffline = true
AutofillURLData = true
database_path = "../links.db"
should_save_offline = true

[[autotag_rule]]
url_pattern = "https://github.com/"
tags = ["GitHub", "To-Read/Codebases"]
should_save_offline = false
22 changes: 15 additions & 7 deletions api/utils/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,30 @@ import (
"github.com/BurntSushi/toml"
)

type AutoTagRule struct {
Pattern string `toml:"pattern"`
Tags []string `toml:"tags"`
ShouldSaveOffline bool `toml:"should_save_offline"`
}
type Config struct {
DatabasePath string
ShouldSaveOffline bool
AutofillURLData bool
DatabasePath string `toml:"database_path"`
ShouldSaveOffline bool `toml:"should_save_offline"`

AutoTagRules []AutoTagRule `toml:"autotag_rule"`
}

var config Config
const ConfigPath = "./bingo.toml"

var config *Config

func LoadConfig() {
_, err := toml.DecodeFile("./bingo.toml", &config)
_, err := toml.DecodeFile(ConfigPath, &config)
Must(err)
}

func GetConfig() Config {
if config == (Config{}) {
if config == nil {
LoadConfig()
}
return config
return *config
}
File renamed without changes.
13 changes: 13 additions & 0 deletions api/utils/formatter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package utils

import (
"bytes"
"text/template"
)

func Format(tpl string, values map[string]string) string {
b := &bytes.Buffer{}
err := template.Must(template.New("").Parse(tpl)).Execute(b, values)
Must(err)
return b.String()
}
10 changes: 10 additions & 0 deletions api/utils/slices.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package utils

func Contains[E comparable](s []E, v E) int {
for i, vs := range s {
if v == vs {
return i
}
}
return -1
}
8 changes: 6 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@
- [x] Update /add route to support title, meta data, etc, auto fill missing data[1]
- [x] Auto fill missing data configuration
- [x] Add support for tags
- [] Auto label
- [] Add /get route
- [x] LinkTree
- [] Config routes
- [] Get
- [] Update
- [] Auto tag
- [] /get routes
- [] all
- [] filter by tags
- [] sort by date added/updated
Expand Down
125 changes: 0 additions & 125 deletions temp/test.go

This file was deleted.

0 comments on commit be82d5a

Please sign in to comment.