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
386af6c1
Commit
386af6c1
authored
Aug 23, 2024
by
Michael Yang
Browse files
passthrough OLLAMA_HOST path to client
parent
90ca8417
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
30 deletions
+27
-30
envconfig/config.go
envconfig/config.go
+3
-7
envconfig/config_test.go
envconfig/config_test.go
+24
-23
No files found.
envconfig/config.go
View file @
386af6c1
...
@@ -30,9 +30,7 @@ func Host() *url.URL {
...
@@ -30,9 +30,7 @@ func Host() *url.URL {
defaultPort
=
"443"
defaultPort
=
"443"
}
}
// trim trailing slashes
hostport
,
path
,
_
:=
strings
.
Cut
(
hostport
,
"/"
)
hostport
=
strings
.
TrimRight
(
hostport
,
"/"
)
host
,
port
,
err
:=
net
.
SplitHostPort
(
hostport
)
host
,
port
,
err
:=
net
.
SplitHostPort
(
hostport
)
if
err
!=
nil
{
if
err
!=
nil
{
host
,
port
=
"127.0.0.1"
,
defaultPort
host
,
port
=
"127.0.0.1"
,
defaultPort
...
@@ -45,15 +43,13 @@ func Host() *url.URL {
...
@@ -45,15 +43,13 @@ func Host() *url.URL {
if
n
,
err
:=
strconv
.
ParseInt
(
port
,
10
,
32
);
err
!=
nil
||
n
>
65535
||
n
<
0
{
if
n
,
err
:=
strconv
.
ParseInt
(
port
,
10
,
32
);
err
!=
nil
||
n
>
65535
||
n
<
0
{
slog
.
Warn
(
"invalid port, using default"
,
"port"
,
port
,
"default"
,
defaultPort
)
slog
.
Warn
(
"invalid port, using default"
,
"port"
,
port
,
"default"
,
defaultPort
)
return
&
url
.
URL
{
port
=
defaultPort
Scheme
:
scheme
,
Host
:
net
.
JoinHostPort
(
host
,
defaultPort
),
}
}
}
return
&
url
.
URL
{
return
&
url
.
URL
{
Scheme
:
scheme
,
Scheme
:
scheme
,
Host
:
net
.
JoinHostPort
(
host
,
port
),
Host
:
net
.
JoinHostPort
(
host
,
port
),
Path
:
path
,
}
}
}
}
...
...
envconfig/config_test.go
View file @
386af6c1
...
@@ -13,34 +13,35 @@ func TestHost(t *testing.T) {
...
@@ -13,34 +13,35 @@ func TestHost(t *testing.T) {
value
string
value
string
expect
string
expect
string
}{
}{
"empty"
:
{
""
,
"127.0.0.1:11434"
},
"empty"
:
{
""
,
"http://127.0.0.1:11434"
},
"only address"
:
{
"1.2.3.4"
,
"1.2.3.4:11434"
},
"only address"
:
{
"1.2.3.4"
,
"http://1.2.3.4:11434"
},
"only port"
:
{
":1234"
,
":1234"
},
"only port"
:
{
":1234"
,
"http://:1234"
},
"address and port"
:
{
"1.2.3.4:1234"
,
"1.2.3.4:1234"
},
"address and port"
:
{
"1.2.3.4:1234"
,
"http://1.2.3.4:1234"
},
"hostname"
:
{
"example.com"
,
"example.com:11434"
},
"hostname"
:
{
"example.com"
,
"http://example.com:11434"
},
"hostname and port"
:
{
"example.com:1234"
,
"example.com:1234"
},
"hostname and port"
:
{
"example.com:1234"
,
"http://example.com:1234"
},
"zero port"
:
{
":0"
,
":0"
},
"zero port"
:
{
":0"
,
"http://:0"
},
"too large port"
:
{
":66000"
,
":11434"
},
"too large port"
:
{
":66000"
,
"http://:11434"
},
"too small port"
:
{
":-1"
,
":11434"
},
"too small port"
:
{
":-1"
,
"http://:11434"
},
"ipv6 localhost"
:
{
"[::1]"
,
"[::1]:11434"
},
"ipv6 localhost"
:
{
"[::1]"
,
"http://[::1]:11434"
},
"ipv6 world open"
:
{
"[::]"
,
"[::]:11434"
},
"ipv6 world open"
:
{
"[::]"
,
"http://[::]:11434"
},
"ipv6 no brackets"
:
{
"::1"
,
"[::1]:11434"
},
"ipv6 no brackets"
:
{
"::1"
,
"http://[::1]:11434"
},
"ipv6 + port"
:
{
"[::1]:1337"
,
"[::1]:1337"
},
"ipv6 + port"
:
{
"[::1]:1337"
,
"http://[::1]:1337"
},
"extra space"
:
{
" 1.2.3.4 "
,
"1.2.3.4:11434"
},
"extra space"
:
{
" 1.2.3.4 "
,
"http://1.2.3.4:11434"
},
"extra quotes"
:
{
"
\"
1.2.3.4
\"
"
,
"1.2.3.4:11434"
},
"extra quotes"
:
{
"
\"
1.2.3.4
\"
"
,
"http://1.2.3.4:11434"
},
"extra space+quotes"
:
{
"
\"
1.2.3.4
\"
"
,
"1.2.3.4:11434"
},
"extra space+quotes"
:
{
"
\"
1.2.3.4
\"
"
,
"http://1.2.3.4:11434"
},
"extra single quotes"
:
{
"'1.2.3.4'"
,
"1.2.3.4:11434"
},
"extra single quotes"
:
{
"'1.2.3.4'"
,
"http://1.2.3.4:11434"
},
"http"
:
{
"http://1.2.3.4"
,
"1.2.3.4:80"
},
"http"
:
{
"http://1.2.3.4"
,
"http://1.2.3.4:80"
},
"http port"
:
{
"http://1.2.3.4:4321"
,
"1.2.3.4:4321"
},
"http port"
:
{
"http://1.2.3.4:4321"
,
"http://1.2.3.4:4321"
},
"https"
:
{
"https://1.2.3.4"
,
"1.2.3.4:443"
},
"https"
:
{
"https://1.2.3.4"
,
"https://1.2.3.4:443"
},
"https port"
:
{
"https://1.2.3.4:4321"
,
"1.2.3.4:4321"
},
"https port"
:
{
"https://1.2.3.4:4321"
,
"https://1.2.3.4:4321"
},
"proxy path"
:
{
"https://example.com/ollama"
,
"https://example.com:443/ollama"
},
}
}
for
name
,
tt
:=
range
cases
{
for
name
,
tt
:=
range
cases
{
t
.
Run
(
name
,
func
(
t
*
testing
.
T
)
{
t
.
Run
(
name
,
func
(
t
*
testing
.
T
)
{
t
.
Setenv
(
"OLLAMA_HOST"
,
tt
.
value
)
t
.
Setenv
(
"OLLAMA_HOST"
,
tt
.
value
)
if
host
:=
Host
();
host
.
Host
!=
tt
.
expect
{
if
host
:=
Host
();
host
.
String
()
!=
tt
.
expect
{
t
.
Errorf
(
"%s: expected %s, got %s"
,
name
,
tt
.
expect
,
host
.
Host
)
t
.
Errorf
(
"%s: expected %s, got %s"
,
name
,
tt
.
expect
,
host
.
String
()
)
}
}
})
})
}
}
...
...
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