-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c3cda2a
commit 01a7cd5
Showing
9 changed files
with
140 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
* chatnio version: | ||
* Go version: | ||
* Operating System: | ||
|
||
### Description | ||
|
||
Describe what you were trying to get done. | ||
Tell us what happened, what went wrong, and what you expected to happen. | ||
|
||
### What I Did | ||
|
||
``` | ||
Paste the command(s) you ran and the output. | ||
If there was a crash, please include the traceback here. | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
name: Test | ||
on: | ||
push: | ||
branches: | ||
- main | ||
jobs: | ||
release: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Use Golang | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: '1.20' | ||
|
||
- name: Test | ||
run: go test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,20 @@ | ||
# ChatNio Go Library | ||
|
||
--- | ||
The official Go library for the Chat Nio API | ||
|
||
- Authors: Deeptrain Team | ||
- Free software: MIT license | ||
- Documentation: https://docs.chatnio.net | ||
|
||
## Features | ||
|
||
- Chat | ||
- Conversation | ||
- Quota | ||
- Subscription and Package | ||
|
||
## Installation | ||
|
||
```shell | ||
go get -u github.com/deeptrain-community/chatnio-api-go | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
github.com/andybalholm/brotli v1.0.5 h1:8uQZIdzKmjc/iuPu7O2ioW48L81FgatrcpfFmiq/cCs= | ||
github.com/andybalholm/brotli v1.0.5/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig= | ||
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc= | ||
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= | ||
github.com/klauspost/compress v1.17.1 h1:NE3C767s2ak2bweCZo3+rdP4U/HoyVXLv/X9f2gPS5g= | ||
github.com/klauspost/compress v1.17.1/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE= | ||
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= | ||
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= | ||
github.com/valyala/fasthttp v1.50.0 h1:H7fweIlBm0rXLs2q0XbalvJ6r0CUPFWK3/bB4N13e9M= | ||
github.com/valyala/fasthttp v1.50.0/go.mod h1:k2zXd82h/7UZc3VOdJ2WaUqt1uZ/XpXAfE9i+HBC3lA= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package chatnio | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
var instance *Instance | ||
|
||
func init() { | ||
instance = NewInstanceFromEnv("CHATNIO_TOKEN") | ||
} | ||
|
||
func TestInstance_GetEndpoint(t *testing.T) { | ||
if instance.GetEndpoint() != "https://api.chatnio.net" { | ||
t.Error("endpoint is not https://api.chatnio.net") | ||
} | ||
} | ||
|
||
func TestInstance_GetChatEndpoint(t *testing.T) { | ||
if instance.GetChatEndpoint() != "wss://api.chatnio.net/chat" { | ||
t.Error("chat endpoint is not correct") | ||
} | ||
} | ||
|
||
func TestInstance_GetHeaders(t *testing.T) { | ||
headers := instance.GetHeaders() | ||
if headers["Authorization"] != "Bearer "+instance.GetApiKey() { | ||
t.Error("authorization header is not correct") | ||
} | ||
} | ||
|
||
func TestInstance_Mix(t *testing.T) { | ||
if instance.Mix("/test") != "https://api.chatnio.net/test" { | ||
t.Error("mix is not correct") | ||
} | ||
} | ||
|
||
func TestInstance_IsAuthenticated(t *testing.T) { | ||
if len(instance.ApiKey) > 0 && !instance.IsAuthenticated() { | ||
t.Error("authentication is not correct") | ||
} | ||
} | ||
|
||
func TestInstance_GetChatApiKey(t *testing.T) { | ||
if instance.IsAuthenticated() && instance.GetChatApiKey() != instance.ApiKey { | ||
t.Error("chat api key is not correct") | ||
} else if !instance.IsAuthenticated() && instance.GetChatApiKey() != "anonymous" { | ||
t.Error("chat api key is not correct") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package utils | ||
|
||
import "testing" | ||
|
||
func TestTrimPrefixes(t *testing.T) { | ||
data := "https://api.chatnio.net" | ||
expected := "api.chatnio.net" | ||
actual := TrimPrefixes(data, "http://", "https://") | ||
if actual != expected { | ||
t.Errorf("expected %s, got %s", expected, actual) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package utils | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestMarshalForm(t *testing.T) { | ||
data := map[string]string{ | ||
"foo": "bar", | ||
} | ||
res := MarshalForm(data) | ||
if res == "" { | ||
t.Error("marshal form failed") | ||
} | ||
|
||
rev := UnmarshalForm[map[string]string](res) | ||
if rev == nil || (*rev)["foo"] != "bar" { | ||
t.Error("form is invalid") | ||
} | ||
} |