Unverified Commit 77ccbf04 authored by Michael Yang's avatar Michael Yang Committed by GitHub
Browse files

Merge pull request #6128 from ollama/mxyng/lint

enable gofmt/gofumpt/goimports/tenv
parents 4addf6b5 b732beba
llm/ext_server/* linguist-vendored llm/ext_server/* linguist-vendored
* text eol=lf
...@@ -273,7 +273,7 @@ jobs: ...@@ -273,7 +273,7 @@ jobs:
if: ${{ startsWith(matrix.os, 'macos-') }} if: ${{ startsWith(matrix.os, 'macos-') }}
- uses: golangci/golangci-lint-action@v6 - uses: golangci/golangci-lint-action@v6
with: with:
args: --timeout 8m0s -v ${{ startsWith(matrix.os, 'windows-') && '' || '--disable gofmt --disable goimports' }} args: --timeout 8m0s -v
test: test:
strategy: strategy:
matrix: matrix:
......
...@@ -7,22 +7,32 @@ linters: ...@@ -7,22 +7,32 @@ linters:
- bodyclose - bodyclose
- containedctx - containedctx
- contextcheck - contextcheck
- errcheck
- exportloopref - exportloopref
- gci
- gocheckcompilerdirectives - gocheckcompilerdirectives
# conditionally enable this on linux/macos - gofmt
# - gofmt - gofumpt
# - goimports - gosimple
- govet
- ineffassign
- intrange - intrange
- makezero
- misspell - misspell
- nilerr - nilerr
- nolintlint - nolintlint
- nosprintfhostport - nosprintfhostport
- staticcheck
- tenv
- testifylint - testifylint
- unconvert - unconvert
- unused - unused
- usestdlibvars
- wastedassign - wastedassign
- whitespace - whitespace
- usestdlibvars linters-settings:
gci:
sections: [standard, default, localmodule]
severity: severity:
default-severity: error default-severity: error
rules: rules:
......
...@@ -18,6 +18,7 @@ import ( ...@@ -18,6 +18,7 @@ import (
"bytes" "bytes"
"context" "context"
"encoding/json" "encoding/json"
"errors"
"fmt" "fmt"
"io" "io"
"net/http" "net/http"
...@@ -172,7 +173,7 @@ func (c *Client) stream(ctx context.Context, method, path string, data any, fn f ...@@ -172,7 +173,7 @@ func (c *Client) stream(ctx context.Context, method, path string, data any, fn f
} }
if errorResponse.Error != "" { if errorResponse.Error != "" {
return fmt.Errorf(errorResponse.Error) return errors.New(errorResponse.Error)
} }
if response.StatusCode >= http.StatusBadRequest { if response.StatusCode >= http.StatusBadRequest {
......
...@@ -2,7 +2,7 @@ package api ...@@ -2,7 +2,7 @@ package api
import ( import (
"encoding/json" "encoding/json"
"fmt" "errors"
"math" "math"
"testing" "testing"
"time" "time"
...@@ -192,7 +192,7 @@ func TestUseMmapFormatParams(t *testing.T) { ...@@ -192,7 +192,7 @@ func TestUseMmapFormatParams(t *testing.T) {
"use_mmap": {"foo"}, "use_mmap": {"foo"},
}, },
exp: nil, exp: nil,
err: fmt.Errorf("invalid bool value [foo]"), err: errors.New("invalid bool value [foo]"),
}, },
} }
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
package lifecycle package lifecycle
import "fmt" import "errors"
func GetStarted() error { func GetStarted() error {
return fmt.Errorf("GetStarted not implemented") return errors.New("not implemented")
} }
...@@ -34,7 +34,6 @@ func GetStarted() error { ...@@ -34,7 +34,6 @@ func GetStarted() error {
Sys: &syscall.SysProcAttr{CreationFlags: CREATE_NEW_CONSOLE, HideWindow: false}, Sys: &syscall.SysProcAttr{CreationFlags: CREATE_NEW_CONSOLE, HideWindow: false},
} }
proc, err := os.StartProcess(args[0], args, attrs) proc, err := os.StartProcess(args[0], args, attrs)
if err != nil { if err != nil {
return fmt.Errorf("unable to start getting started shell %w", err) return fmt.Errorf("unable to start getting started shell %w", err)
} }
......
...@@ -27,7 +27,7 @@ func InitLogging() { ...@@ -27,7 +27,7 @@ func InitLogging() {
// TODO - write one-line to the app.log file saying we're running in console mode to help avoid confusion // TODO - write one-line to the app.log file saying we're running in console mode to help avoid confusion
} else { } else {
rotateLogs(AppLogFile) rotateLogs(AppLogFile)
logFile, err = os.OpenFile(AppLogFile, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0755) logFile, err = os.OpenFile(AppLogFile, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0o755)
if err != nil { if err != nil {
slog.Error(fmt.Sprintf("failed to create server log %v", err)) slog.Error(fmt.Sprintf("failed to create server log %v", err))
return return
......
...@@ -5,5 +5,5 @@ package lifecycle ...@@ -5,5 +5,5 @@ package lifecycle
import "log/slog" import "log/slog"
func ShowLogs() { func ShowLogs() {
slog.Warn("ShowLogs not yet implemented") slog.Warn("not implemented")
} }
...@@ -17,7 +17,7 @@ func TestRotateLogs(t *testing.T) { ...@@ -17,7 +17,7 @@ func TestRotateLogs(t *testing.T) {
// No log exists // No log exists
rotateLogs(logFile) rotateLogs(logFile)
require.NoError(t, os.WriteFile(logFile, []byte("1"), 0644)) require.NoError(t, os.WriteFile(logFile, []byte("1"), 0o644))
assert.FileExists(t, logFile) assert.FileExists(t, logFile)
// First rotation // First rotation
rotateLogs(logFile) rotateLogs(logFile)
...@@ -32,7 +32,7 @@ func TestRotateLogs(t *testing.T) { ...@@ -32,7 +32,7 @@ func TestRotateLogs(t *testing.T) {
assert.NoFileExists(t, logFile) assert.NoFileExists(t, logFile)
for i := 2; i <= LogRotationCount+1; i++ { for i := 2; i <= LogRotationCount+1; i++ {
require.NoError(t, os.WriteFile(logFile, []byte(strconv.Itoa(i)), 0644)) require.NoError(t, os.WriteFile(logFile, []byte(strconv.Itoa(i)), 0o644))
assert.FileExists(t, logFile) assert.FileExists(t, logFile)
rotateLogs(logFile) rotateLogs(logFile)
assert.NoFileExists(t, logFile) assert.NoFileExists(t, logFile)
......
...@@ -55,7 +55,7 @@ func start(ctx context.Context, command string) (*exec.Cmd, error) { ...@@ -55,7 +55,7 @@ func start(ctx context.Context, command string) (*exec.Cmd, error) {
} }
rotateLogs(ServerLogFile) rotateLogs(ServerLogFile)
logFile, err := os.OpenFile(ServerLogFile, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0755) logFile, err := os.OpenFile(ServerLogFile, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0o755)
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to create server log: %w", err) return nil, fmt.Errorf("failed to create server log: %w", err)
} }
......
...@@ -15,6 +15,7 @@ import ( ...@@ -15,6 +15,7 @@ import (
"path" "path"
"path/filepath" "path/filepath"
"runtime" "runtime"
"strconv"
"strings" "strings"
"time" "time"
...@@ -46,7 +47,7 @@ func IsNewReleaseAvailable(ctx context.Context) (bool, UpdateResponse) { ...@@ -46,7 +47,7 @@ func IsNewReleaseAvailable(ctx context.Context) (bool, UpdateResponse) {
query.Add("os", runtime.GOOS) query.Add("os", runtime.GOOS)
query.Add("arch", runtime.GOARCH) query.Add("arch", runtime.GOARCH)
query.Add("version", version.Version) query.Add("version", version.Version)
query.Add("ts", fmt.Sprintf("%d", time.Now().Unix())) query.Add("ts", strconv.FormatInt(time.Now().Unix(), 10))
nonce, err := auth.NewNonce(rand.Reader, 16) nonce, err := auth.NewNonce(rand.Reader, 16)
if err != nil { if err != nil {
......
...@@ -4,9 +4,9 @@ package lifecycle ...@@ -4,9 +4,9 @@ package lifecycle
import ( import (
"context" "context"
"fmt" "errors"
) )
func DoUpgrade(cancel context.CancelFunc, done chan int) error { func DoUpgrade(cancel context.CancelFunc, done chan int) error {
return fmt.Errorf("DoUpgrade not yet implemented") return errors.New("not implemented")
} }
...@@ -2,6 +2,7 @@ package lifecycle ...@@ -2,6 +2,7 @@ package lifecycle
import ( import (
"context" "context"
"errors"
"fmt" "fmt"
"log/slog" "log/slog"
"os" "os"
...@@ -15,7 +16,7 @@ func DoUpgrade(cancel context.CancelFunc, done chan int) error { ...@@ -15,7 +16,7 @@ func DoUpgrade(cancel context.CancelFunc, done chan int) error {
return fmt.Errorf("failed to lookup downloads: %s", err) return fmt.Errorf("failed to lookup downloads: %s", err)
} }
if len(files) == 0 { if len(files) == 0 {
return fmt.Errorf("no update downloads found") return errors.New("no update downloads found")
} else if len(files) > 1 { } else if len(files) > 1 {
// Shouldn't happen // Shouldn't happen
slog.Warn(fmt.Sprintf("multiple downloads found, using first one %v", files)) slog.Warn(fmt.Sprintf("multiple downloads found, using first one %v", files))
...@@ -64,7 +65,7 @@ func DoUpgrade(cancel context.CancelFunc, done chan int) error { ...@@ -64,7 +65,7 @@ func DoUpgrade(cancel context.CancelFunc, done chan int) error {
} }
} else { } else {
// TODO - some details about why it didn't start, or is this a pedantic error case? // TODO - some details about why it didn't start, or is this a pedantic error case?
return fmt.Errorf("installer process did not start") return errors.New("installer process did not start")
} }
// TODO should we linger for a moment and check to make sure it's actually running by checking the pid? // TODO should we linger for a moment and check to make sure it's actually running by checking the pid?
......
...@@ -3,11 +3,11 @@ ...@@ -3,11 +3,11 @@
package tray package tray
import ( import (
"fmt" "errors"
"github.com/ollama/ollama/app/tray/commontray" "github.com/ollama/ollama/app/tray/commontray"
) )
func InitPlatformTray(icon, updateIcon []byte) (commontray.OllamaTray, error) { func InitPlatformTray(icon, updateIcon []byte) (commontray.OllamaTray, error) {
return nil, fmt.Errorf("NOT IMPLEMENTED YET") return nil, errors.New("not implemented")
} }
...@@ -11,9 +11,7 @@ import ( ...@@ -11,9 +11,7 @@ import (
"golang.org/x/sys/windows" "golang.org/x/sys/windows"
) )
var ( var quitOnce sync.Once
quitOnce sync.Once
)
func (t *winTray) Run() { func (t *winTray) Run() {
nativeLoop() nativeLoop()
......
...@@ -13,8 +13,9 @@ import ( ...@@ -13,8 +13,9 @@ import (
"sync" "sync"
"unsafe" "unsafe"
"github.com/ollama/ollama/app/tray/commontray"
"golang.org/x/sys/windows" "golang.org/x/sys/windows"
"github.com/ollama/ollama/app/tray/commontray"
) )
// Helpful sources: https://github.com/golang/exp/blob/master/shiny/driver/internal/win32 // Helpful sources: https://github.com/golang/exp/blob/master/shiny/driver/internal/win32
...@@ -414,7 +415,7 @@ func iconBytesToFilePath(iconBytes []byte) (string, error) { ...@@ -414,7 +415,7 @@ func iconBytesToFilePath(iconBytes []byte) (string, error) {
iconFilePath := filepath.Join(os.TempDir(), "ollama_temp_icon_"+dataHash) iconFilePath := filepath.Join(os.TempDir(), "ollama_temp_icon_"+dataHash)
if _, err := os.Stat(iconFilePath); os.IsNotExist(err) { if _, err := os.Stat(iconFilePath); os.IsNotExist(err) {
if err := os.WriteFile(iconFilePath, iconBytes, 0644); err != nil { if err := os.WriteFile(iconFilePath, iconBytes, 0o644); err != nil {
return "", err return "", err
} }
} }
......
...@@ -5,6 +5,7 @@ import ( ...@@ -5,6 +5,7 @@ import (
"context" "context"
"crypto/rand" "crypto/rand"
"encoding/base64" "encoding/base64"
"errors"
"fmt" "fmt"
"io" "io"
"log/slog" "log/slog"
...@@ -78,7 +79,7 @@ func Sign(ctx context.Context, bts []byte) (string, error) { ...@@ -78,7 +79,7 @@ func Sign(ctx context.Context, bts []byte) (string, error) {
publicKey := ssh.MarshalAuthorizedKey(privateKey.PublicKey()) publicKey := ssh.MarshalAuthorizedKey(privateKey.PublicKey())
parts := bytes.Split(publicKey, []byte(" ")) parts := bytes.Split(publicKey, []byte(" "))
if len(parts) < 2 { if len(parts) < 2 {
return "", fmt.Errorf("malformed public key") return "", errors.New("malformed public key")
} }
signedData, err := privateKey.Sign(rand.Reader, bts) signedData, err := privateKey.Sign(rand.Reader, bts)
......
...@@ -1160,7 +1160,7 @@ func checkServerHeartbeat(cmd *cobra.Command, _ []string) error { ...@@ -1160,7 +1160,7 @@ func checkServerHeartbeat(cmd *cobra.Command, _ []string) error {
return err return err
} }
if err := startApp(cmd.Context(), client); err != nil { if err := startApp(cmd.Context(), client); err != nil {
return fmt.Errorf("could not connect to ollama app, is it running?") return errors.New("could not connect to ollama app, is it running?")
} }
} }
return nil return nil
......
...@@ -604,7 +604,7 @@ func getImageData(filePath string) ([]byte, error) { ...@@ -604,7 +604,7 @@ func getImageData(filePath string) ([]byte, error) {
// Check if the file size exceeds 100MB // Check if the file size exceeds 100MB
var maxSize int64 = 100 * 1024 * 1024 // 100MB in bytes var maxSize int64 = 100 * 1024 * 1024 // 100MB in bytes
if info.Size() > maxSize { if info.Size() > maxSize {
return nil, fmt.Errorf("file size exceeds maximum limit (100MB)") return nil, errors.New("file size exceeds maximum limit (100MB)")
} }
buf = make([]byte, info.Size()) buf = make([]byte, info.Size())
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment