Rename to client

This commit is contained in:
Owen
2025-02-20 22:04:06 -05:00
parent 5ec1aac0d1
commit c5098f0cd0
13 changed files with 74 additions and 74 deletions

View File

@@ -10,7 +10,7 @@ import (
"sync"
"time"
"github.com/fosrl/newt/logger"
"github.com/fosrl/client/logger"
"github.com/gorilla/websocket"
)
@@ -45,10 +45,10 @@ func (c *Client) OnConnect(callback func() error) {
c.onConnect = callback
}
// NewClient creates a new Newt client
func NewClient(newtID, secret string, endpoint string, opts ...ClientOption) (*Client, error) {
// NewClient creates a new Client client
func NewClient(clientID, secret string, endpoint string, opts ...ClientOption) (*Client, error) {
config := &Config{
NewtID: newtID,
ClientID: clientID,
Secret: secret,
Endpoint: endpoint,
}
@@ -152,9 +152,9 @@ func (c *Client) getToken() (string, error) {
// If we already have a token, try to use it
if c.config.Token != "" {
tokenCheckData := map[string]interface{}{
"newtId": c.config.NewtID,
"secret": c.config.Secret,
"token": c.config.Token,
"clientId": c.config.ClientID,
"secret": c.config.Secret,
"token": c.config.Token,
}
jsonData, err := json.Marshal(tokenCheckData)
if err != nil {
@@ -164,7 +164,7 @@ func (c *Client) getToken() (string, error) {
// Create a new request
req, err := http.NewRequest(
"POST",
baseEndpoint+"/api/v1/auth/newt/get-token",
baseEndpoint+"/api/v1/auth/client/get-token",
bytes.NewBuffer(jsonData),
)
if err != nil {
@@ -196,8 +196,8 @@ func (c *Client) getToken() (string, error) {
// Get a new token
tokenData := map[string]interface{}{
"newtId": c.config.NewtID,
"secret": c.config.Secret,
"clientId": c.config.ClientID,
"secret": c.config.Secret,
}
jsonData, err := json.Marshal(tokenData)
if err != nil {
@@ -207,7 +207,7 @@ func (c *Client) getToken() (string, error) {
// Create a new request
req, err := http.NewRequest(
"POST",
baseEndpoint+"/api/v1/auth/newt/get-token",
baseEndpoint+"/api/v1/auth/client/get-token",
bytes.NewBuffer(jsonData),
)
if err != nil {

View File

@@ -12,11 +12,11 @@ func getConfigPath() string {
var configDir string
switch runtime.GOOS {
case "darwin":
configDir = filepath.Join(os.Getenv("HOME"), "Library", "Application Support", "newt-client")
configDir = filepath.Join(os.Getenv("HOME"), "Library", "Application Support", "client-client")
case "windows":
configDir = filepath.Join(os.Getenv("APPDATA"), "newt-client")
configDir = filepath.Join(os.Getenv("APPDATA"), "client-client")
default: // linux and others
configDir = filepath.Join(os.Getenv("HOME"), ".config", "newt-client")
configDir = filepath.Join(os.Getenv("HOME"), ".config", "client-client")
}
if err := os.MkdirAll(configDir, 0755); err != nil {
@@ -27,7 +27,7 @@ func getConfigPath() string {
}
func (c *Client) loadConfig() error {
if c.config.NewtID != "" && c.config.Secret != "" && c.config.Endpoint != "" {
if c.config.ClientID != "" && c.config.Secret != "" && c.config.Endpoint != "" {
return nil
}
@@ -45,8 +45,8 @@ func (c *Client) loadConfig() error {
return err
}
if c.config.NewtID == "" {
c.config.NewtID = config.NewtID
if c.config.ClientID == "" {
c.config.ClientID = config.ClientID
}
if c.config.Token == "" {
c.config.Token = config.Token

View File

@@ -1,7 +1,7 @@
package websocket
type Config struct {
NewtID string `json:"newtId"`
ClientID string `json:"clientId"`
Secret string `json:"secret"`
Token string `json:"token"`
Endpoint string `json:"endpoint"`