From 1c07c4f9888fd4bfd52bbad859e114ae31fc4311 Mon Sep 17 00:00:00 2001 From: Ben Watkins Date: Fri, 18 Oct 2019 23:16:48 -0500 Subject: [PATCH] start using a local storage approach I have begun the work towards a local storage approach vs storing data remotely. --- cli/go.mod | 2 +- cli/main.go | 40 ++++++++++++++-------------------------- cli/model.go | 17 +++++++++++++++++ cli/storage.go | 1 + 4 files changed, 33 insertions(+), 27 deletions(-) create mode 100644 cli/model.go create mode 100644 cli/storage.go diff --git a/cli/go.mod b/cli/go.mod index 0863924..06dcc7c 100644 --- a/cli/go.mod +++ b/cli/go.mod @@ -2,4 +2,4 @@ module github.com/OutdatedVersion/notes go 1.13 -require github.com/mattn/go-sqlite3 v1.11.0 // indirect +require github.com/mattn/go-sqlite3 v1.11.0 diff --git a/cli/main.go b/cli/main.go index 96399c6..20ace71 100644 --- a/cli/main.go +++ b/cli/main.go @@ -1,36 +1,24 @@ package main import ( - "bytes" - "encoding/json" - "io/ioutil" + "flag" "log" - "net/http" - "os" - "strings" -) - -func main() { - requestBody := map[string]string{"content": strings.Join(os.Args[1:], " ")} - json, err := json.Marshal(requestBody) - - if err != nil { - log.Fatalln("We could not convert the input into JSON", err) - } - response, err := http.Post("https://bens.wtf/notes/api/@me", "application/json", bytes.NewBuffer(json)) - - if err != nil { - log.Fatalln("We could not make the request", err) - } + _ "github.com/mattn/go-sqlite3" +) - defer response.Body.Close() +var ( + channelFlag = flag.String("c", "@me", "name of the channel to save into") +) - body, err := ioutil.ReadAll(response.Body) +func main() { + flag.Parse() - if err != nil { - log.Fatalln("Failed to read response body", err) - } + log.Printf("content: %s\n", flag.Args()) + log.Printf("channel: %s\n", *channelFlag) - log.Print("http response: ", string(body)) + // TODO(ben): configurable database location + // database, _ := sql.Open("sqlite3", "./notes.db") + // statement, _ := database.Prepare("CREATE TABLE IF NOT EXISTS notes (id BLOB PRIMARY KEY, content TEXT, active TINYINT, created_at DATETIME);") + // statement.Exec() } diff --git a/cli/model.go b/cli/model.go new file mode 100644 index 0000000..872af5e --- /dev/null +++ b/cli/model.go @@ -0,0 +1,17 @@ +package main + +import "time" + +// Channel defines the top level bucket for notes to be held in +type Channel struct { + ID string `json:"id"` + Name string `json:"name"` + Notes []Note `json:"notes"` +} + +// Note defines the primary item we store +type Note struct { + Content string `json:"content"` + Active bool `json:"active"` + CreatedAt *time.Time `json:"created_at"` +} diff --git a/cli/storage.go b/cli/storage.go new file mode 100644 index 0000000..06ab7d0 --- /dev/null +++ b/cli/storage.go @@ -0,0 +1 @@ +package main