Skip to content

Commit 5cdca12

Browse files
authored
Merge pull request #9 from tasnimzotder/temp
Temp
2 parents bb418e1 + 111db22 commit 5cdca12

19 files changed

+329
-183
lines changed

.DS_Store

0 Bytes
Binary file not shown.

.github/workflows/release.yml

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
name: Client Release
2+
3+
on:
4+
push:
5+
branches: [ 'main' ]
6+
tags:
7+
- 'v*'
8+
9+
jobs:
10+
build:
11+
runs-on: ${{ matrix.os }}
12+
strategy:
13+
matrix:
14+
os: [macos-14, ubuntu-latest]
15+
arch: [amd64, arm64]
16+
exclude:
17+
- os: macos-14
18+
arch: amd64
19+
- os: ubuntu-latest
20+
arch: arm64
21+
22+
defaults:
23+
run:
24+
working-directory: ./client
25+
26+
steps:
27+
- name: Checkout repository
28+
uses: actions/checkout@v3
29+
30+
- name: Set up Go
31+
uses: actions/setup-go@v4
32+
with:
33+
go-version: 1.22
34+
35+
- name: Install dependencies
36+
run: go mod download -x
37+
38+
- name: test
39+
run: go test -v ./...
40+
41+
- name: Set GOOS for macOS
42+
if: matrix.os == 'macos-14'
43+
run: echo "GOOS=darwin" >> $GITHUB_ENV
44+
45+
- name: Set GOOS for Ubuntu
46+
if: matrix.os == 'ubuntu-latest'
47+
run: echo "GOOS=linux" >> $GITHUB_ENV
48+
49+
- name: Build client
50+
env:
51+
CGO_ENABLED: 1
52+
GOOS: ${{ env.GOOS }}
53+
GOARCH: ${{ matrix.arch }}
54+
run: go build -o client
55+
56+
- name: Upload client artifact
57+
uses: actions/upload-artifact@v3
58+
with:
59+
name: tchat-${{ env.GOOS }}-${{ matrix.arch }}
60+
path: ./client
61+
62+
# release:
63+
# # if: startsWith(github.ref, 'refs/tags/v')
64+
# needs: build
65+
# runs-on: ubuntu-latest
66+
67+
# steps:
68+
# - name: Checkout code
69+
# uses: actions/checkout@v2
70+
71+
# - name: Download client artifact
72+
# uses: actions/download-artifact@v3
73+
# with:
74+
# path: .
75+
76+
# - name: Create Release
77+
# id: create_release
78+
# uses: actions/create-release@v1
79+
# env:
80+
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
81+
# with:
82+
# tag_name: ${{ github.ref }}
83+
# release_name: Release ${{ github.ref }}
84+
# body: |
85+
# Changes in this Release
86+
# - First Change
87+
# - Second Change
88+
# draft: true
89+
# prerelease: false
90+
91+
# - name: Upload release assets
92+
# uses: actions/upload-release-asset@v1
93+
# env:
94+
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
95+
# with:
96+
# upload_url: ${{ steps.create_release.outputs.upload_url }}
97+
# asset_path: ./tchat-*-*
98+
# asset_name: tchat-*-*
99+
# asset_content_type: application/octet-stream

.idea/vcs.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
dist/

client/Makefile

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,10 @@ build_dev:
22
go build -o bin/tchat main.go
33

44
build:
5-
GOOS=linux GOARCH=amd64 go build -o bin/tchat.linux.amd64 main.go
6-
GOOS=linux GOARCH=arm64 go build -o bin/tchat.linux.arm64 main.go
7-
GOOS=darwin GOARCH=arm64 go build -o bin/tchat.darwin.arm64 main.go
8-
GOOS=windows GOARCH=amd64 go build -o bin/tchat.windows.amd64.exe main.go
5+
CGO_ENABLED=1 go build -o bin/tchat main.go
96

107
bin:
118
sudo cp bin/tchat /usr/local/bin/tchat
129

1310
test:
14-
go test -v -count=1 ./... -cover
11+
go test -v -count=1 ./... -cover

client/cmd/connection_cmd.go

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@ import (
1616
"github.com/tasnimzotder/tchat/_client/pkg/models"
1717
)
1818

19-
func connectionCmd(apiClient *client.Client) *cobra.Command {
19+
func connectionCmd(storageClient *storage.Storage) *cobra.Command {
2020
return &cobra.Command{
2121
Use: "conn",
2222
Short: "conn",
2323
Run: func(cmd *cobra.Command, args []string) {
24-
connectionCmdHandler(apiClient, cmd, args)
24+
connectionCmdHandler(storageClient, cmd, args)
2525
},
2626
}
2727
}
2828

29-
func connectionCmdHandler(apiClient *client.Client, cmd *cobra.Command, args []string) {
29+
func connectionCmdHandler(storageClient *storage.Storage, cmd *cobra.Command, args []string) {
3030
connectionTypes := []string{"begin", "create", "list", "remove"}
3131

3232
commandPrompt := promptui.Select{
@@ -41,29 +41,29 @@ func connectionCmdHandler(apiClient *client.Client, cmd *cobra.Command, args []s
4141

4242
switch connectionType {
4343
case "begin":
44-
beginConnectionHandler(apiClient)
44+
beginConnectionHandler(storageClient)
4545
case "create":
46-
createConnectionHandler(apiClient)
46+
createConnectionHandler(storageClient)
4747
case "list":
48-
listConnectionHandler()
48+
listConnectionHandler(storageClient)
4949
case "remove":
5050
// todo: implement
5151
}
5252
}
5353

54-
func beginConnectionHandler(apiClient *client.Client) {
54+
func beginConnectionHandler(storageClient *storage.Storage) {
5555
display.PrintMessage("info", "Beginning connection")
5656
display.PrintMessage("info", "This setting will store your public RSA key on the server for other users to download \nand use to send you encrypted messages.\n")
5757

58-
sqlite, err := storage.NewSQLiteStorage()
59-
if err != nil {
60-
display.PrintMessage("error", "Failed to create storage")
61-
return
62-
}
63-
64-
defer sqlite.Close()
58+
//sqlite, err := storage.NewSQLiteStorage()
59+
//if err != nil {
60+
// display.PrintMessage("error", "Failed to create storage")
61+
// return
62+
//}
63+
//
64+
//defer sqlite.Close()
6565

66-
publicKey, err := sqlite.GetPublicRSAKey()
66+
publicKey, err := storageClient.GetPublicRSAKey()
6767
if err != nil {
6868
display.PrintMessage("error", "Failed to get public RSA key")
6969
return
@@ -72,7 +72,7 @@ func beginConnectionHandler(apiClient *client.Client) {
7272
publicKeyBase64 := cryptography.EncodeBase64(publicKey)
7373

7474
// user
75-
user, err := sqlite.GetLastUser()
75+
user, err := storageClient.GetLastUser()
7676
if err != nil {
7777
display.PrintMessage("error", "Failed to get user")
7878
return
@@ -92,7 +92,7 @@ func beginConnectionHandler(apiClient *client.Client) {
9292
}
9393

9494
// start connection
95-
err = apiClient.CreateConnection(connectionRequest)
95+
err = storageClient.API.CreateConnection(connectionRequest)
9696
if err != nil {
9797
display.PrintMessage("error", "Failed to create connection")
9898
return
@@ -118,7 +118,7 @@ func beginConnectionHandler(apiClient *client.Client) {
118118
table.Render()
119119
}
120120

121-
func createConnectionHandler(apiClient *client.Client) {
121+
func createConnectionHandler(storageClient *storage.Storage) {
122122
userIdPrompt := promptui.Prompt{
123123
Label: "Enter the user ID",
124124
Validate: func(input string) error {
@@ -157,7 +157,7 @@ func createConnectionHandler(apiClient *client.Client) {
157157
}
158158

159159
// get connection
160-
connection, err := apiClient.GetConnection(request)
160+
connection, err := storageClient.API.GetConnection(request)
161161
if err != nil {
162162
display.PrintMessage("error", "Failed to get connection")
163163
return
@@ -191,15 +191,15 @@ func createConnectionHandler(apiClient *client.Client) {
191191
}
192192

193193
// add contact
194-
sqlite, err := storage.NewSQLiteStorage()
195-
if err != nil {
196-
display.PrintMessage("error", "Failed to create storage")
197-
return
198-
}
199-
200-
defer sqlite.Close()
201-
202-
err = sqlite.SaveContact(contact)
194+
//sqlite, err := storage.NewSQLiteStorage()
195+
//if err != nil {
196+
// display.PrintMessage("error", "Failed to create storage")
197+
// return
198+
//}
199+
//
200+
//defer sqlite.Close()
201+
202+
err = storageClient.SaveContact(contact)
203203
if err != nil {
204204
display.PrintMessage("error", "Failed to save contact")
205205
return
@@ -208,16 +208,16 @@ func createConnectionHandler(apiClient *client.Client) {
208208
display.PrintMessage("info", "Contact added successfully")
209209
}
210210

211-
func listConnectionHandler() {
212-
sqlite, err := storage.NewSQLiteStorage()
213-
if err != nil {
214-
display.PrintMessage("error", "Failed to create storage")
215-
return
216-
}
217-
218-
defer sqlite.Close()
211+
func listConnectionHandler(storageClient *storage.Storage) {
212+
//sqlite, err := storage.NewSQLiteStorage()
213+
//if err != nil {
214+
// display.PrintMessage("error", "Failed to create storage")
215+
// return
216+
//}
217+
//
218+
//defer sqlite.Close()
219219

220-
contacts, err := sqlite.GetContacts()
220+
contacts, err := storageClient.GetContacts()
221221
if err != nil {
222222
display.PrintMessage("error", "Failed to get contacts")
223223
return

client/cmd/message_cmd.go

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,28 @@ import (
77
"github.com/spf13/cobra"
88
"github.com/tasnimzotder/tchat/_client/internal/display"
99
"github.com/tasnimzotder/tchat/_client/internal/storage"
10-
"github.com/tasnimzotder/tchat/_client/pkg/client"
1110
)
1211

13-
func messageCmd(apiClient *client.Client) *cobra.Command {
12+
func messageCmd(storageClient *storage.Storage) *cobra.Command {
1413
_messageCmd := &cobra.Command{
1514
Use: "msg",
1615
Short: "Message commands",
1716
Run: func(cmd *cobra.Command, args []string) {
18-
messageCmdHandler(apiClient, cmd, args)
17+
messageCmdHandler(storageClient, cmd, args)
1918
},
2019
}
2120

2221
_messageCmd.Flags().BoolP("clear", "c", false, "Clear messages")
2322
_messageCmd.Flags().BoolP("display", "d", false, "Display nth Message (default: last)")
2423
_messageCmd.Flags().BoolP("save", "s", false, "Save nth Message (default: last)")
2524

26-
_messageCmd.AddCommand(sendMessageCmd(apiClient))
25+
_messageCmd.AddCommand(sendMessageCmd(storageClient))
2726
// messageCmd.AddCommand(getMessagesCmd(apiClient))
2827

2928
return _messageCmd
3029
}
3130

32-
func messageCmdHandler(apiClient *client.Client, cmd *cobra.Command, args []string) error {
31+
func messageCmdHandler(storageClient *storage.Storage, cmd *cobra.Command, args []string) error {
3332
clearFlag, err := cmd.Flags().GetBool("clear")
3433
if err != nil {
3534
return err
@@ -50,25 +49,25 @@ func messageCmdHandler(apiClient *client.Client, cmd *cobra.Command, args []stri
5049
fmt.Println("Saving last message")
5150
}
5251

53-
sqlite, err := storage.NewSQLiteStorage()
54-
if err != nil {
55-
return err
56-
}
57-
58-
defer sqlite.Close()
52+
//sqlite, err := storage.NewSQLiteStorage()
53+
//if err != nil {
54+
// return err
55+
//}
56+
//
57+
//defer sqlite.Close()
5958

60-
userID, err := sqlite.GetUserID()
59+
userID, err := storageClient.GetUserID()
6160
if err != nil {
6261
return err
6362
}
6463

65-
messages, err := apiClient.GetMessages(userID)
64+
messages, err := storageClient.API.GetMessages(userID)
6665
if err != nil {
6766
return err
6867
}
6968

7069
if clearFlag {
71-
err = sqlite.DeleteMessages()
70+
err = storageClient.DeleteMessages()
7271

7372
if err != nil {
7473
return err
@@ -78,13 +77,13 @@ func messageCmdHandler(apiClient *client.Client, cmd *cobra.Command, args []stri
7877
}
7978

8079
// save messages
81-
err = sqlite.SaveMessages(messages)
80+
err = storageClient.SaveMessages(messages)
8281
if err != nil {
8382
return err
8483
}
8584

8685
// get messages
87-
messages, err = sqlite.GetMessages()
86+
messages, err = storageClient.GetMessages()
8887
if err != nil {
8988
return err
9089
}
@@ -93,7 +92,6 @@ func messageCmdHandler(apiClient *client.Client, cmd *cobra.Command, args []stri
9392
for i, j := 0, len(messages)-1; i < j; i, j = i+1, j-1 {
9493
messages[i], messages[j] = messages[j], messages[i]
9594
}
96-
9795

9896
if displayFlag {
9997
// todo: implement
@@ -121,9 +119,9 @@ func messageCmdHandler(apiClient *client.Client, cmd *cobra.Command, args []stri
121119
}
122120

123121
message := messages[len(messages)-idx]
124-
display.DisplaySingleMessage(message)
122+
display.DisplaySingleMessage(storageClient, message)
125123
} else {
126-
display.DisplayMessages(messages)
124+
display.DisplayMessages(storageClient, messages)
127125
}
128126

129127
return nil

0 commit comments

Comments
 (0)