Skip to content

Commit

Permalink
add: basic configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
abhijit-hota committed Apr 30, 2022
1 parent e4e8688 commit cfdcf15
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 6 deletions.
2 changes: 2 additions & 0 deletions api/bingo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
DatabasePath = "../links.db"
ShouldSaveOffline = true
3 changes: 2 additions & 1 deletion api/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ var db *sql.DB

func InitializeDB() (db *sql.DB) {
var err error
db, err = sql.Open("sqlite3", "../links.db")
conf := utils.GetConfig()
db, err = sql.Open("sqlite3", conf.DatabasePath)
utils.Must(err)

_, err = db.Exec(`
Expand Down
24 changes: 24 additions & 0 deletions api/utils/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package utils

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

type Config struct {
DatabasePath string
ShouldSaveOffline bool
}

var config Config

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

func GetConfig() Config {
if config == (Config{}) {
LoadConfig()
}
return config
}
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ go 1.18

require (
fyne.io/fyne/v2 v2.1.4
github.com/BurntSushi/toml v1.1.0
github.com/atotto/clipboard v0.1.4
github.com/gin-gonic/gin v1.7.7
github.com/mattn/go-sqlite3 v1.14.12
)

Expand All @@ -13,7 +15,6 @@ require (
github.com/fredbi/uri v0.0.0-20181227131451-3dcfdacbaaf3 // indirect
github.com/fsnotify/fsnotify v1.4.9 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/gin-gonic/gin v1.7.7 // indirect
github.com/go-gl/gl v0.0.0-20210813123233-e4099ee2221f // indirect
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20211024062804-40e447a793be // indirect
github.com/go-playground/locales v0.13.0 // indirect
Expand Down
4 changes: 3 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ fyne.io/fyne/v2 v2.1.4 h1:bt1+28++kAzRzPB0GM2EuSV4cnl8rXNX4cjfd8G06Rc=
fyne.io/fyne/v2 v2.1.4/go.mod h1:p+E/Dh+wPW8JwR2DVcsZ9iXgR9ZKde80+Y+40Is54AQ=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/toml v0.4.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/BurntSushi/toml v1.1.0 h1:ksErzDEI1khOiGPgpwuI7x2ebx/uXQNw7xJpn9Eq1+I=
github.com/BurntSushi/toml v1.1.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/Kodeworks/golang-image-ico v0.0.0-20141118225523-73f0f4cfade9/go.mod h1:7uhhqiBaR4CpN0k9rMjOtjpcfGd6DG2m04zQxKnWQ0I=
github.com/akavel/rsrc v0.8.0/go.mod h1:uLoCtb9J+EyAqh+26kdrTgmzRBFPGOolLWKpdxkKq+c=
github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4=
Expand All @@ -23,6 +25,7 @@ github.com/go-gl/gl v0.0.0-20210813123233-e4099ee2221f/go.mod h1:wjpnOv6ONl2SuJS
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20211024062804-40e447a793be h1:Z28GdQBfKOL8tNHjvaDn3wHDO7AzTRkmAXvHvnopp98=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20211024062804-40e447a793be/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
github.com/go-playground/assert/v2 v2.0.1 h1:MsBgLAaY856+nPRTKrp3/OZK38U/wa0CcBYNjji3q3A=
github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q=
github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8=
Expand Down Expand Up @@ -76,7 +79,6 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo=
github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=
github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs=
github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
Expand Down
7 changes: 4 additions & 3 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/atotto/clipboard"
"golang.design/x/hotkey"
"golang.design/x/hotkey/mainthread"

"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/widget"
Expand All @@ -30,18 +31,18 @@ func ListenForHotKey() {
fmt.Println(i)
url, err := clipboard.ReadAll()
handle(err)
http.Post("http://localhost:8080/add", "text", strings.NewReader(url))
http.Post("http://localhost:8080/add", "text/plain", strings.NewReader(url))
}
}

func UI() {
a := app.New()
w := a.NewWindow("Hello World")
log.Println("s")

w.SetContent(widget.NewLabel("Hello World!"))
w.ShowAndRun()
}

func main() {
UI()
mainthread.Init(ListenForHotKey)
}

0 comments on commit cfdcf15

Please sign in to comment.