Skip to content

Commit 698dcc6

Browse files
committed
share type between desktop and server
1 parent c9a4f18 commit 698dcc6

File tree

6 files changed

+261
-86
lines changed

6 files changed

+261
-86
lines changed

desktop/auth.go

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,17 @@ import (
77
"io"
88
"net/http"
99

10+
"github.com/ut-code/Raxcel/server/types"
1011
"github.com/zalando/go-keyring"
1112
)
1213

13-
type RegisterRequest struct {
14-
Email string `json:"email"`
15-
Password string `json:"password"`
16-
}
17-
1814
type SignupResult struct {
1915
UserId string `json:"userId"`
2016
Error string `json:"error"`
2117
}
2218

2319
func (a *App) Signup(email, password string) SignupResult {
24-
postData := RegisterRequest{
20+
postData := types.SignupRequest{
2521
Email: email,
2622
Password: password,
2723
}
@@ -49,7 +45,7 @@ func (a *App) Signup(email, password string) SignupResult {
4945
Error: fmt.Sprintf("Failed to read response: %v", err),
5046
}
5147
}
52-
var serverResponse map[string]string
48+
var serverResponse types.SignupResponse
5349
err = json.Unmarshal(body, &serverResponse)
5450
if err != nil {
5551
return SignupResult{
@@ -60,27 +56,22 @@ func (a *App) Signup(email, password string) SignupResult {
6056
if resp.StatusCode != http.StatusCreated {
6157
return SignupResult{
6258
UserId: "",
63-
Error: serverResponse["error"],
59+
Error: serverResponse.Error,
6460
}
6561
}
6662
return SignupResult{
67-
UserId: serverResponse["userId"],
63+
UserId: serverResponse.UserId,
6864
Error: "",
6965
}
7066
}
7167

72-
type LoginRequest struct {
73-
Email string `json:"email"`
74-
Password string `json:"password"`
75-
}
76-
7768
type SigninResult struct {
7869
Token string `json:"token"`
7970
Error string `json:"error"`
8071
}
8172

8273
func (a *App) Signin(email, password string) SigninResult {
83-
postData := LoginRequest{
74+
postData := types.SigninRequest{
8475
Email: email,
8576
Password: password,
8677
}
@@ -110,7 +101,7 @@ func (a *App) Signin(email, password string) SigninResult {
110101
}
111102
}
112103

113-
var serverResponse map[string]string
104+
var serverResponse types.SigninResponse
114105
err = json.Unmarshal(body, &serverResponse)
115106
if err != nil {
116107
return SigninResult{
@@ -121,10 +112,10 @@ func (a *App) Signin(email, password string) SigninResult {
121112
if resp.StatusCode != http.StatusOK {
122113
return SigninResult{
123114
Token: "",
124-
Error: serverResponse["error"],
115+
Error: serverResponse.Error,
125116
}
126117
}
127-
token := serverResponse["token"]
118+
token := serverResponse.Token
128119
err = keyring.Set("Raxcel", "raxcel-user", token)
129120
if err != nil {
130121
return SigninResult{
@@ -164,21 +155,28 @@ func (a *App) GetCurrentUser() GetCurrentUserResult {
164155
Error: fmt.Sprint(err),
165156
}
166157
}
167-
var serverResponse map[string]string
158+
var serverResponse types.GetCurrentUserResponse
168159
if err := json.Unmarshal(body, &serverResponse); err != nil {
169160
return GetCurrentUserResult{
170161
UserId: "",
171162
Error: fmt.Sprint(err),
172163
}
173164
}
174-
if serverResponse["error"] != "" {
165+
if serverResponse.AuthMiddlewareReturn != nil {
166+
return GetCurrentUserResult{
167+
UserId: "",
168+
// Error: serverResponse.AuthMiddlewareReturn.MiddlewareError, でも同じこと
169+
Error: serverResponse.MiddlewareError,
170+
}
171+
}
172+
if serverResponse.GetCurrentUserResponse.Error != "" {
175173
return GetCurrentUserResult{
176174
UserId: "",
177-
Error: serverResponse["error"],
175+
Error: serverResponse.Error,
178176
}
179177
}
180178
return GetCurrentUserResult{
181-
UserId: serverResponse["userId"],
179+
UserId: serverResponse.UserId,
182180
Error: "",
183181
}
184182
}

desktop/go.mod

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,69 @@
11
module github.com/ut-code/Raxcel/desktop
22

3-
go 1.24
4-
5-
toolchain go1.24.6
3+
go 1.24.6
64

75
require (
86
github.com/joho/godotenv v1.5.1
7+
github.com/ut-code/Raxcel/server v0.0.0-00010101000000-000000000000
98
github.com/wailsapp/wails/v2 v2.10.2
109
github.com/zalando/go-keyring v0.2.6
1110
)
1211

1312
require (
1413
al.essio.dev/pkg/shellescape v1.5.1 // indirect
14+
cloud.google.com/go v0.116.0 // indirect
15+
cloud.google.com/go/auth v0.9.3 // indirect
16+
cloud.google.com/go/compute/metadata v0.5.0 // indirect
1517
github.com/bep/debounce v1.2.1 // indirect
1618
github.com/danieljoos/wincred v1.2.2 // indirect
1719
github.com/go-ole/go-ole v1.3.0 // indirect
1820
github.com/godbus/dbus/v5 v5.1.0 // indirect
21+
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
22+
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
23+
github.com/google/go-cmp v0.6.0 // indirect
24+
github.com/google/s2a-go v0.1.8 // indirect
1925
github.com/google/uuid v1.6.0 // indirect
26+
github.com/googleapis/enterprise-certificate-proxy v0.3.4 // indirect
2027
github.com/gorilla/websocket v1.5.3 // indirect
28+
github.com/jackc/pgpassfile v1.0.0 // indirect
29+
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
30+
github.com/jackc/pgx/v5 v5.6.0 // indirect
31+
github.com/jackc/puddle/v2 v2.2.2 // indirect
2132
github.com/jchv/go-winloader v0.0.0-20210711035445-715c2860da7e // indirect
22-
github.com/labstack/echo/v4 v4.13.3 // indirect
33+
github.com/jinzhu/inflection v1.0.0 // indirect
34+
github.com/jinzhu/now v1.1.5 // indirect
35+
github.com/labstack/echo/v4 v4.13.4 // indirect
2336
github.com/labstack/gommon v0.4.2 // indirect
2437
github.com/leaanthony/go-ansi-parser v1.6.1 // indirect
2538
github.com/leaanthony/gosod v1.0.4 // indirect
2639
github.com/leaanthony/slicer v1.6.0 // indirect
2740
github.com/leaanthony/u v1.1.1 // indirect
28-
github.com/mattn/go-colorable v0.1.13 // indirect
41+
github.com/mattn/go-colorable v0.1.14 // indirect
2942
github.com/mattn/go-isatty v0.0.20 // indirect
3043
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c // indirect
3144
github.com/pkg/errors v0.9.1 // indirect
45+
github.com/resend/resend-go/v3 v3.0.0 // indirect
3246
github.com/rivo/uniseg v0.4.7 // indirect
3347
github.com/samber/lo v1.49.1 // indirect
3448
github.com/tkrajina/go-reflector v0.5.8 // indirect
3549
github.com/valyala/bytebufferpool v1.0.0 // indirect
3650
github.com/valyala/fasttemplate v1.2.2 // indirect
3751
github.com/wailsapp/go-webview2 v1.0.19 // indirect
3852
github.com/wailsapp/mimetype v1.4.1 // indirect
39-
golang.org/x/crypto v0.33.0 // indirect
40-
golang.org/x/net v0.35.0 // indirect
41-
golang.org/x/sys v0.30.0 // indirect
42-
golang.org/x/text v0.22.0 // indirect
53+
go.opencensus.io v0.24.0 // indirect
54+
golang.org/x/crypto v0.38.0 // indirect
55+
golang.org/x/net v0.40.0 // indirect
56+
golang.org/x/sync v0.14.0 // indirect
57+
golang.org/x/sys v0.33.0 // indirect
58+
golang.org/x/text v0.25.0 // indirect
59+
google.golang.org/genai v1.32.0 // indirect
60+
google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1 // indirect
61+
google.golang.org/grpc v1.66.2 // indirect
62+
google.golang.org/protobuf v1.34.2 // indirect
63+
gorm.io/driver/postgres v1.6.0 // indirect
64+
gorm.io/gorm v1.25.10 // indirect
4365
)
4466

4567
// replace github.com/wailsapp/wails/v2 v2.10.2 => /
68+
69+
replace github.com/ut-code/Raxcel/server => ../server

0 commit comments

Comments
 (0)