Skip to content
Merged
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
4 changes: 2 additions & 2 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ func apiNote(dir string, w http.ResponseWriter, r *http.Request, readOnly bool)
noteCache = nil
populateCache(dir)

response := map[string]interface{}{
response := map[string]any{
"Filename": filename,
"Deleted": true,
}
Expand Down Expand Up @@ -292,7 +292,7 @@ func apiNote(dir string, w http.ResponseWriter, r *http.Request, readOnly bool)
w.Write(jsonResponse)
}

func apiRuntime(dir string, w http.ResponseWriter, r *http.Request, opts webOptions) {
func apiRuntime(dir string, w http.ResponseWriter, _ *http.Request, opts webOptions) {
runtimeResponse := GetRuntimeInfo(dir, opts)
jsonResponse, err := json.Marshal(runtimeResponse)
if err != nil {
Expand Down
4 changes: 1 addition & 3 deletions cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"bufio"
"fmt"
"io/ioutil"
"log"
"os"
"path/filepath"
Expand Down Expand Up @@ -42,8 +41,7 @@ func populateCache(dir string) {
}

noteCache = make(map[string]*Note)

files, err := ioutil.ReadDir(dir)
files, err := os.ReadDir(dir)
if err != nil {
log.Fatalf("could not read directory: %s\n", err)
}
Expand Down
3 changes: 1 addition & 2 deletions filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,8 @@ func evaluateFilterQuery(query string, input string) (bool, error) {
}
}
matches = matches && orMatch
} else if strings.HasPrefix(token, "!") {
} else if term, ok := strings.CutPrefix(token, "!"); ok {
// NOT logic
term := strings.TrimPrefix(token, "!")
if strings.Contains(input, term) {
matches = false
break
Expand Down
5 changes: 2 additions & 3 deletions notesium.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"fmt"
"io"
"io/fs"
"io/ioutil"
"log"
"net"
"net/http"
Expand Down Expand Up @@ -241,7 +240,7 @@ func notesiumLinks(dir string, opts linksOptions, w io.Writer) {
}

func notesiumLines(dir string, opts linesOptions, w io.Writer) {
files, err := ioutil.ReadDir(dir)
files, err := os.ReadDir(dir)
if err != nil {
log.Fatalf("Could not read directory: %s\n", err)
}
Expand Down Expand Up @@ -566,7 +565,7 @@ func notesiumVersion(opts versionOptions, w io.Writer) {
fmt.Fprintf(w, "platform:%s/%s\n", runtime.GOOS, runtime.GOARCH)
fmt.Fprintf(w, "latest.version:%s\n", latest.Version)
fmt.Fprintf(w, "latest.published:%s\n", latest.PublishedAt)
fmt.Fprintf(w, "latest.release:%s\n", latest.HtmlUrl)
fmt.Fprintf(w, "latest.release:%s\n", latest.HTMLURL)
}
return
}
Expand Down
14 changes: 7 additions & 7 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Environment:

type Command struct {
Name string
Options interface{}
Options any
}

type newOptions struct {
Expand Down Expand Up @@ -272,10 +272,10 @@ func parseOptions(args []string) (Command, error) {
case "stats":
opts := statsOptions{}
for _, opt := range args[1:] {
switch {
case opt == "--color":
switch opt {
case "--color":
opts.color = defaultColor()
case opt == "--table":
case "--table":
opts.table = true
default:
return Command{}, fmt.Errorf("unrecognized option: %s", opt)
Expand Down Expand Up @@ -356,10 +356,10 @@ func parseOptions(args []string) (Command, error) {
case "version":
opts := versionOptions{}
for _, opt := range args[1:] {
switch {
case opt == "--verbose":
switch opt {
case "--verbose":
opts.verbose = true
case opt == "--check":
case "--check":
opts.check = true
default:
return Command{}, fmt.Errorf("unrecognized option: %s", opt)
Expand Down
4 changes: 2 additions & 2 deletions runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type BuildInfo struct {
GitVersion string `json:"gitversion"`
Buildtime string `json:"buildtime"`
GoVersion string `json:"goversion"`
LatestReleaseUrl string `json:"latest-release-url"`
LatestReleaseURL string `json:"latest-release-url"`
}

type MemoryInfo struct {
Expand Down Expand Up @@ -55,7 +55,7 @@ func GetRuntimeInfo(dir string, webOpts webOptions) RuntimeResponse {
GitVersion: gitversion,
Buildtime: buildtime,
GoVersion: runtime.Version(),
LatestReleaseUrl: latestReleaseUrl,
LatestReleaseURL: latestReleaseURL,
},
Memory: MemoryInfo{
MemoryAlloc: bytesToHumanReadable(memStats.Alloc),
Expand Down
6 changes: 3 additions & 3 deletions sort.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ func getSortedNotes(sortBy string) []*Note {

func sortLinesByField(lines []string, separator string, fieldIndex int) {
sort.Slice(lines, func(i, j int) bool {
sub_i := strings.SplitN(lines[i], separator, fieldIndex+1)[fieldIndex]
sub_j := strings.SplitN(lines[j], separator, fieldIndex+1)[fieldIndex]
return sub_i < sub_j
subI := strings.SplitN(lines[i], separator, fieldIndex+1)[fieldIndex]
subJ := strings.SplitN(lines[j], separator, fieldIndex+1)[fieldIndex]
return subI < subJ
})
}
2 changes: 1 addition & 1 deletion tests/version.bats
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ _gobuild() {
go build -o /tmp/notesium-test-version/$gitversion -ldflags "
-X main.gitversion=$gitversion \
-X main.buildtime=2024-01-02T01:02:03Z \
-X main.latestReleaseUrl=http://127.0.0.1:8882/latest.json"
-X main.latestReleaseURL=http://127.0.0.1:8882/latest.json"
}

_mock_latest_release() {
Expand Down
8 changes: 4 additions & 4 deletions version.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import (
// 1:semver (2:major 3:minor 4:patch 5:prerelease 6:prereleaseV) 7:commits 8:hash 9:dirty
var gitVersionRegex = regexp.MustCompile(`^v((0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-(alpha|beta|rc)(?:\.(0|[1-9]\d*))?)?)-(0|[1-9]\d*)-g([0-9a-fA-F]+)(-dirty)?$`)

var latestReleaseUrl = "https://api.github.com/repos/alonswartz/notesium/releases/latest"
var latestReleaseURL = "https://api.github.com/repos/alonswartz/notesium/releases/latest"

type releaseInfo struct {
Version string `json:"-"`
TagName string `json:"tag_name"`
HtmlUrl string `json:"html_url"`
HTMLURL string `json:"html_url"`
PublishedAt string `json:"published_at"`
}

Expand All @@ -43,7 +43,7 @@ func getVersion(gitVersion string) string {
func getLatestReleaseInfo() (releaseInfo, error) {
var release releaseInfo

req, err := http.NewRequest("GET", latestReleaseUrl, nil)
req, err := http.NewRequest("GET", latestReleaseURL, nil)
if err != nil {
return release, fmt.Errorf("error creating request: %s", err)
}
Expand All @@ -66,7 +66,7 @@ func getLatestReleaseInfo() (releaseInfo, error) {
return release, fmt.Errorf("error decoding response: %s", err)
}

if release.TagName == "" || release.HtmlUrl == "" || release.PublishedAt == "" {
if release.TagName == "" || release.HTMLURL == "" || release.PublishedAt == "" {
return release, fmt.Errorf("missing required field in response")
}

Expand Down