Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
ollama
Commits
77ccbf04
Unverified
Commit
77ccbf04
authored
Aug 02, 2024
by
Michael Yang
Committed by
GitHub
Aug 02, 2024
Browse files
Merge pull request #6128 from ollama/mxyng/lint
enable gofmt/gofumpt/goimports/tenv
parents
4addf6b5
b732beba
Changes
68
Show whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
44 additions
and
31 deletions
+44
-31
.gitattributes
.gitattributes
+1
-0
.github/workflows/test.yaml
.github/workflows/test.yaml
+1
-1
.golangci.yaml
.golangci.yaml
+14
-4
api/client.go
api/client.go
+2
-1
api/types_test.go
api/types_test.go
+2
-2
app/lifecycle/getstarted_nonwindows.go
app/lifecycle/getstarted_nonwindows.go
+2
-2
app/lifecycle/getstarted_windows.go
app/lifecycle/getstarted_windows.go
+0
-1
app/lifecycle/logging.go
app/lifecycle/logging.go
+1
-1
app/lifecycle/logging_nonwindows.go
app/lifecycle/logging_nonwindows.go
+1
-1
app/lifecycle/logging_test.go
app/lifecycle/logging_test.go
+2
-2
app/lifecycle/server.go
app/lifecycle/server.go
+1
-1
app/lifecycle/updater.go
app/lifecycle/updater.go
+2
-1
app/lifecycle/updater_nonwindows.go
app/lifecycle/updater_nonwindows.go
+2
-2
app/lifecycle/updater_windows.go
app/lifecycle/updater_windows.go
+3
-2
app/tray/tray_nonwindows.go
app/tray/tray_nonwindows.go
+2
-2
app/tray/wintray/eventloop.go
app/tray/wintray/eventloop.go
+1
-3
app/tray/wintray/tray.go
app/tray/wintray/tray.go
+3
-2
auth/auth.go
auth/auth.go
+2
-1
cmd/cmd.go
cmd/cmd.go
+1
-1
cmd/interactive.go
cmd/interactive.go
+1
-1
No files found.
.gitattributes
View file @
77ccbf04
llm/ext_server/* linguist-vendored
llm/ext_server/* linguist-vendored
* text eol=lf
.github/workflows/test.yaml
View file @
77ccbf04
...
@@ -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
:
...
...
.golangci.yaml
View file @
77ccbf04
...
@@ -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
:
...
...
api/client.go
View file @
77ccbf04
...
@@ -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
{
...
...
api/types_test.go
View file @
77ccbf04
...
@@ -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]"
),
},
},
}
}
...
...
app/lifecycle/getstarted_nonwindows.go
View file @
77ccbf04
...
@@ -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"
)
}
}
app/lifecycle/getstarted_windows.go
View file @
77ccbf04
...
@@ -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
)
}
}
...
...
app/lifecycle/logging.go
View file @
77ccbf04
...
@@ -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
,
0
o
755
)
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
...
...
app/lifecycle/logging_nonwindows.go
View file @
77ccbf04
...
@@ -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 ye
t implemented"
)
slog
.
Warn
(
"
no
t implemented"
)
}
}
app/lifecycle/logging_test.go
View file @
77ccbf04
...
@@ -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"
),
0
o
644
))
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
)),
0
o
644
))
assert
.
FileExists
(
t
,
logFile
)
assert
.
FileExists
(
t
,
logFile
)
rotateLogs
(
logFile
)
rotateLogs
(
logFile
)
assert
.
NoFileExists
(
t
,
logFile
)
assert
.
NoFileExists
(
t
,
logFile
)
...
...
app/lifecycle/server.go
View file @
77ccbf04
...
@@ -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
,
0
o
755
)
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
)
}
}
...
...
app/lifecycle/updater.go
View file @
77ccbf04
...
@@ -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
{
...
...
app/lifecycle/updater_nonwindows.go
View file @
77ccbf04
...
@@ -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 ye
t implemented"
)
return
errors
.
New
(
"no
t implemented"
)
}
}
app/lifecycle/updater_windows.go
View file @
77ccbf04
...
@@ -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?
...
...
app/tray/tray_nonwindows.go
View file @
77ccbf04
...
@@ -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
"
)
}
}
app/tray/wintray/eventloop.go
View file @
77ccbf04
...
@@ -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
()
...
...
app/tray/wintray/tray.go
View file @
77ccbf04
...
@@ -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
,
0
o
644
);
err
!=
nil
{
return
""
,
err
return
""
,
err
}
}
}
}
...
...
auth/auth.go
View file @
77ccbf04
...
@@ -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
)
...
...
cmd/cmd.go
View file @
77ccbf04
...
@@ -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
...
...
cmd/interactive.go
View file @
77ccbf04
...
@@ -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
())
...
...
Prev
1
2
3
4
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment