mirror of
https://github.com/dnote/dnote
synced 2026-03-14 14:35:50 +01:00
Fix issues from gometalinter and add code badges (#74)
This commit is contained in:
parent
a7e7364332
commit
4d25b84363
9 changed files with 28 additions and 47 deletions
|
|
@ -38,3 +38,5 @@ Please refer to [commands](/COMMANDS.md).
|
|||
MIT
|
||||
|
||||
[](https://travis-ci.org/dnote-io/cli)
|
||||
[](https://goreportcard.com/report/github.com/dnote-io/cli)
|
||||
[](https://golangci.com)
|
||||
|
|
|
|||
|
|
@ -71,8 +71,8 @@ func newRun(ctx infra.DnoteCtx) core.RunEFunc {
|
|||
fpath := core.GetDnoteTmpContentPath(ctx)
|
||||
|
||||
e := ioutil.WriteFile(fpath, []byte(targetNote.Content), 0644)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "Failed to prepare editor content")
|
||||
if e != nil {
|
||||
return errors.Wrap(e, "Failed to prepare editor content")
|
||||
}
|
||||
|
||||
e = core.GetEditorInput(ctx, fpath, &newContent)
|
||||
|
|
|
|||
|
|
@ -36,7 +36,9 @@ func newRun(ctx infra.DnoteCtx) core.RunEFunc {
|
|||
log.Printf("API key: ")
|
||||
|
||||
var apiKey string
|
||||
fmt.Scanln(&apiKey)
|
||||
if _, err := fmt.Scanln(&apiKey); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if apiKey == "" {
|
||||
return errors.New("Empty API key")
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import (
|
|||
"compress/gzip"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
|
||||
|
|
@ -100,6 +101,9 @@ func newRun(ctx infra.DnoteCtx) core.RunEFunc {
|
|||
|
||||
// Update bookmark
|
||||
ts, err := core.ReadTimestamp(ctx)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "Failed to read the timestamp")
|
||||
}
|
||||
ts.Bookmark = respData.Bookmark
|
||||
|
||||
err = core.WriteTimestamp(ctx, ts)
|
||||
|
|
@ -157,7 +161,7 @@ func compressActions(actions []core.Action) ([]byte, error) {
|
|||
return buf.Bytes(), nil
|
||||
}
|
||||
|
||||
func postActions(ctx infra.DnoteCtx, APIKey string, payload *bytes.Buffer) (*http.Response, error) {
|
||||
func postActions(ctx infra.DnoteCtx, APIKey string, payload io.Reader) (*http.Response, error) {
|
||||
endpoint := fmt.Sprintf("%s/v1/sync", ctx.APIEndpoint)
|
||||
req, err := http.NewRequest("POST", endpoint, payload)
|
||||
if err != nil {
|
||||
|
|
|
|||
33
core/core.go
33
core/core.go
|
|
@ -242,12 +242,7 @@ func WriteDnote(ctx infra.DnoteCtx, dnote infra.Dnote) error {
|
|||
|
||||
notePath := GetDnotePath(ctx)
|
||||
|
||||
err = ioutil.WriteFile(notePath, d, 0644)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
return ioutil.WriteFile(notePath, d, 0644)
|
||||
}
|
||||
|
||||
func WriteConfig(ctx infra.DnoteCtx, config infra.Config) error {
|
||||
|
|
@ -258,12 +253,7 @@ func WriteConfig(ctx infra.DnoteCtx, config infra.Config) error {
|
|||
|
||||
configPath := GetConfigPath(ctx)
|
||||
|
||||
err = ioutil.WriteFile(configPath, d, 0644)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
return ioutil.WriteFile(configPath, d, 0644)
|
||||
}
|
||||
|
||||
// LogAction appends the action to the action log and updates the last_action
|
||||
|
|
@ -297,12 +287,7 @@ func WriteActionLog(ctx infra.DnoteCtx, actions []Action) error {
|
|||
return errors.Wrap(err, "Failed to marshal newly generated actions to JSON")
|
||||
}
|
||||
|
||||
err = ioutil.WriteFile(path, d, 0644)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
return ioutil.WriteFile(path, d, 0644)
|
||||
}
|
||||
|
||||
func ClearActionLog(ctx infra.DnoteCtx) error {
|
||||
|
|
@ -336,11 +321,7 @@ func ReadActionLog(ctx infra.DnoteCtx) ([]Action, error) {
|
|||
}
|
||||
|
||||
err = json.Unmarshal(b, &ret)
|
||||
if err != nil {
|
||||
return ret, err
|
||||
}
|
||||
|
||||
return ret, nil
|
||||
return ret, err
|
||||
}
|
||||
|
||||
func ReadConfig(ctx infra.DnoteCtx) (infra.Config, error) {
|
||||
|
|
@ -353,11 +334,7 @@ func ReadConfig(ctx infra.DnoteCtx) (infra.Config, error) {
|
|||
}
|
||||
|
||||
err = yaml.Unmarshal(b, &ret)
|
||||
if err != nil {
|
||||
return ret, err
|
||||
}
|
||||
|
||||
return ret, nil
|
||||
return ret, err
|
||||
}
|
||||
|
||||
func UpdateLastActionTimestamp(ctx infra.DnoteCtx, val int64) error {
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ func TestReduceAddNote(t *testing.T) {
|
|||
Data: b,
|
||||
Timestamp: 1517629805,
|
||||
}
|
||||
if err := Reduce(ctx, action); err != nil {
|
||||
if err = Reduce(ctx, action); err != nil {
|
||||
t.Fatal(errors.Wrap(err, "Failed to process action"))
|
||||
}
|
||||
|
||||
|
|
@ -70,7 +70,7 @@ func TestReduceAddNote_SortByAddedOn(t *testing.T) {
|
|||
Data: b,
|
||||
Timestamp: 1515199944,
|
||||
}
|
||||
if err := Reduce(ctx, action); err != nil {
|
||||
if err = Reduce(ctx, action); err != nil {
|
||||
t.Fatal(errors.Wrap(err, "Failed to process action"))
|
||||
}
|
||||
|
||||
|
|
@ -115,7 +115,7 @@ func TestReduceRemoveNote(t *testing.T) {
|
|||
Data: b,
|
||||
Timestamp: 1517629805,
|
||||
}
|
||||
if err := Reduce(ctx, action); err != nil {
|
||||
if err = Reduce(ctx, action); err != nil {
|
||||
t.Fatal(errors.Wrap(err, "Failed to process action"))
|
||||
}
|
||||
|
||||
|
|
@ -197,7 +197,7 @@ func TestReduceAddBook(t *testing.T) {
|
|||
Data: b,
|
||||
Timestamp: 1517629805,
|
||||
}
|
||||
if err := Reduce(ctx, action); err != nil {
|
||||
if err = Reduce(ctx, action); err != nil {
|
||||
t.Fatal(errors.Wrap(err, "Failed to process action"))
|
||||
}
|
||||
|
||||
|
|
@ -229,7 +229,7 @@ func TestReduceRemoveBook(t *testing.T) {
|
|||
Data: b,
|
||||
Timestamp: 1517629805,
|
||||
}
|
||||
if err := Reduce(ctx, action); err != nil {
|
||||
if err = Reduce(ctx, action); err != nil {
|
||||
t.Fatal(errors.Wrap(err, "Failed to process action"))
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ var binaryName = "test-dnote"
|
|||
|
||||
func TestMain(m *testing.M) {
|
||||
if err := exec.Command("go", "build", "-o", binaryName).Run(); err != nil {
|
||||
log.Printf(errors.Wrap(err, "Failed to build a binary").Error())
|
||||
log.Print(errors.Wrap(err, "Failed to build a binary").Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
|
|
@ -66,7 +66,7 @@ func TestInit(t *testing.T) {
|
|||
runDnoteCmd(ctx)
|
||||
|
||||
// Test
|
||||
if !utils.FileExists(fmt.Sprintf("%s", ctx.DnoteDir)) {
|
||||
if !utils.FileExists(ctx.DnoteDir) {
|
||||
t.Errorf("dnote directory was not initialized")
|
||||
}
|
||||
if !utils.FileExists(fmt.Sprintf("%s/%s", ctx.DnoteDir, core.DnoteFilename)) {
|
||||
|
|
|
|||
|
|
@ -186,11 +186,7 @@ func readSchema(ctx infra.DnoteCtx) (schema, error) {
|
|||
}
|
||||
|
||||
err = yaml.Unmarshal(b, &ret)
|
||||
if err != nil {
|
||||
return ret, err
|
||||
}
|
||||
|
||||
return ret, nil
|
||||
return ret, err
|
||||
}
|
||||
|
||||
func writeSchema(ctx infra.DnoteCtx, s schema) error {
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ func CopyFile(src, dest string) error {
|
|||
return errors.Wrap(err, "Failed to copy the file content")
|
||||
}
|
||||
|
||||
if err := out.Sync(); err != nil {
|
||||
if err = out.Sync(); err != nil {
|
||||
return errors.Wrap(err, "Failed to flush the output file to disk")
|
||||
}
|
||||
|
||||
|
|
@ -91,12 +91,12 @@ func CopyFile(src, dest string) error {
|
|||
return errors.Wrap(err, "Failed to get file info for the input file")
|
||||
}
|
||||
|
||||
if err := os.Chmod(dest, fi.Mode()); err != nil {
|
||||
if err = os.Chmod(dest, fi.Mode()); err != nil {
|
||||
return errors.Wrap(err, "Failed to copy permission to the output file")
|
||||
}
|
||||
|
||||
// Close the output file
|
||||
if err := out.Close(); err != nil {
|
||||
if err = out.Close(); err != nil {
|
||||
return errors.Wrap(err, "Failed to close the output file")
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue