Skip to content
This repository was archived by the owner on Sep 21, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cli/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
40 changes: 14 additions & 26 deletions cli/main.go
Original file line number Diff line number Diff line change
@@ -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);")
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wip testing, needs to be moved

// statement.Exec()
}
17 changes: 17 additions & 0 deletions cli/model.go
Original file line number Diff line number Diff line change
@@ -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
Comment thread
OutdatedVersion marked this conversation as resolved.
type Note struct {
Content string `json:"content"`
Active bool `json:"active"`
CreatedAt *time.Time `json:"created_at"`
}
1 change: 1 addition & 0 deletions cli/storage.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package main