Split the client and server into different Go packages and binaries to make it easier to do cross platform builds and to be more unixy
This commit is contained in:
parent
5794ea43a3
commit
138c54d75c
30
Client.md
30
Client.md
@ -1,9 +1,9 @@
|
||||
# GoSmartKeyboard Client
|
||||
|
||||
When GoSmartKeyboard is started in client mode, it does the following:
|
||||
When the GoSmartKeyboard client is started, it does the following:
|
||||
|
||||
1. Load the connection URL from the second CLI argument.
|
||||
2. Load the auth token from the environment variable `KEYBOARD_AUTH` or stdin.
|
||||
1. Load the connection URL from the first CLI argument.
|
||||
2. Load the auth token from the environment variable `KEYBOARD_AUTH` or stdin if it does not exist.
|
||||
3. Connect to the server.
|
||||
4 Send the auth token to the server.
|
||||
5. If the server responds with "authenticated", we start reading keys from stdin and sending them to the server until EOF.
|
||||
@ -13,7 +13,7 @@ When GoSmartKeyboard is started in client mode, it does the following:
|
||||
``` go
|
||||
--- handle client command
|
||||
|
||||
if len(os.Args) > 1 && os.Args[1] == "connect" {
|
||||
if len(os.Args) > 1 {
|
||||
@{get client fifo input file from environment}
|
||||
@{setup client}
|
||||
if clientFifoInputFileExists {
|
||||
@ -175,3 +175,25 @@ addXDoToolIfNonQWERTY := func(message string)(string) {
|
||||
|
||||
---
|
||||
```
|
||||
|
||||
|
||||
``` go
|
||||
--- /client/main-client.go
|
||||
package main
|
||||
import (
|
||||
"strings"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"bufio"
|
||||
"log"
|
||||
"fmt"
|
||||
"os"
|
||||
@{gorilla/websocket import string}
|
||||
|
||||
)
|
||||
|
||||
func main(){@{handle client command}}
|
||||
|
||||
|
||||
---
|
||||
```
|
||||
|
9
Makefile
9
Makefile
@ -10,9 +10,12 @@ clean:
|
||||
rm go.sum
|
||||
|
||||
build: tangle
|
||||
- cd smartkeyboard && go mod init keyboard.voidnet.tech
|
||||
- cd smartkeyboard && go mod tidy
|
||||
- cd smartkeyboard && go build -o ../bin/keyboard
|
||||
- cd smartkeyboard/server && go mod init keyboard.voidnet.tech
|
||||
- cd smartkeyboard/server && go mod tidy
|
||||
- cd smartkeyboard/server && go build -o ../../bin/keyboard
|
||||
- cd smartkeyboard/client && go mod init keyboard.voidnet.tech
|
||||
- cd smartkeyboard/client && go mod tidy
|
||||
- cd smartkeyboard/client && go build -o ../../bin/keyboard-client
|
||||
|
||||
|
||||
test: tangle
|
||||
|
@ -65,8 +65,6 @@ Then we can start the web server and listen for websocket connections.
|
||||
|
||||
func main(){
|
||||
|
||||
@{handle client command}
|
||||
|
||||
tokenBase64, _ := auth.ProvisionToken()
|
||||
if len(tokenBase64) > 0 {
|
||||
fmt.Println("This is your authentication token, it will only be shown once: " + tokenBase64)
|
||||
@ -79,7 +77,7 @@ Then we can start the web server and listen for websocket connections.
|
||||
---
|
||||
|
||||
|
||||
--- /main.go
|
||||
--- /server/main.go
|
||||
package main
|
||||
|
||||
import(
|
||||
|
@ -53,7 +53,7 @@ func StartServer() {
|
||||
---
|
||||
|
||||
|
||||
--- /server/server.go
|
||||
--- /server/server/server.go
|
||||
package server
|
||||
|
||||
import(
|
||||
|
@ -98,7 +98,7 @@ The following is the structure of the authentication package.
|
||||
Both CheckAuthToken and ProvisionToken are exported.
|
||||
The former is used by the server on client connect and the latter is called on startup.
|
||||
|
||||
--- /auth/auth.go
|
||||
--- /server/auth/auth.go
|
||||
package auth
|
||||
|
||||
import(
|
||||
|
Loading…
Reference in New Issue
Block a user