Skip to content

Commit

Permalink
chore: lint
Browse files Browse the repository at this point in the history
  • Loading branch information
javascriptizer1 committed Jun 13, 2024
1 parent 8cc8865 commit 8513c00
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 25 deletions.
8 changes: 4 additions & 4 deletions service/chat/internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import (
)

type Config struct {
Env string `env:"ENV" env-default:"local"`
GRPC GRPCConfig
Env string `env:"ENV" env-default:"local"`
GRPC GRPCConfig
GRPCAuth GRPCAuthConfig
HTTP HTTPConfig
DB DBConfig
HTTP HTTPConfig
DB DBConfig
}

type GRPCConfig struct {
Expand Down
9 changes: 7 additions & 2 deletions service/cli/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,13 @@ func Execute() {
Use: "gchat",
Short: "CLI client for chat service",
Version: "0.0.1",
PersistentPreRun: func(cmd *cobra.Command, args []string) {
sp.TokenManager(ctx).Load()
PersistentPreRun: func(_ *cobra.Command, _ []string) {
err := sp.TokenManager(ctx).Load()

if err != nil {
colog.Warn("load config error: %v", err)
}

},
}

Expand Down
2 changes: 1 addition & 1 deletion service/cli/cmd/connect_chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ func newConnectChatCommand(ctx context.Context, sp *app.ServiceProvider) *cobra.

func addConnectChatFlags(cmd *cobra.Command) {
cmd.Flags().String("chat-id", "", "ID of the chat")
cmd.MarkFlagRequired("chat-id")
_ = cmd.MarkFlagRequired("chat-id")
}
4 changes: 2 additions & 2 deletions service/cli/cmd/create_chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ func newCreateChatCommand(ctx context.Context, sp *app.ServiceProvider) *cobra.C
}

func addCreateChatFlags(cmd *cobra.Command) {
cmd.Flags().StringArray("emails", []string{}, "Emails of the users in the chat")
cmd.MarkFlagRequired("emails")
_ = cmd.Flags().StringArray("emails", []string{}, "Emails of the users in the chat")
_ = cmd.MarkFlagRequired("emails")
}
4 changes: 2 additions & 2 deletions service/cli/cmd/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@ func newLoginCommand(ctx context.Context, sp *app.ServiceProvider) *cobra.Comman
func addLoginFlags(cmd *cobra.Command) {
cmd.Flags().StringP("login", "l", "", "Email of the user")
cmd.Flags().StringP("password", "p", "", "Password of the user")
cmd.MarkFlagRequired("login")
cmd.MarkFlagRequired("password")
_ = cmd.MarkFlagRequired("login")
_ = cmd.MarkFlagRequired("password")
}
8 changes: 4 additions & 4 deletions service/cli/cmd/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ func addRegisterFlags(cmd *cobra.Command) {
cmd.Flags().StringP("email", "e", "", "Email of the user")
cmd.Flags().StringP("password", "p", "", "Password of the user")
cmd.Flags().StringP("password-confirm", "c", "", "Password confirmation")
cmd.MarkFlagRequired("name")
cmd.MarkFlagRequired("email")
cmd.MarkFlagRequired("password")
cmd.MarkFlagRequired("password-confirm")
_ = cmd.MarkFlagRequired("name")
_ = cmd.MarkFlagRequired("email")
_ = cmd.MarkFlagRequired("password")
_ = cmd.MarkFlagRequired("password-confirm")
}
4 changes: 2 additions & 2 deletions service/cli/cmd/send_mesage.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ func newSendMessageCommand(ctx context.Context, sp *app.ServiceProvider) *cobra.
func addSendMessageFlags(cmd *cobra.Command) {
cmd.Flags().String("chat-id", "", "ID of the chat")
cmd.Flags().String("text", "", "Text of the message")
cmd.MarkFlagRequired("chat-id")
cmd.MarkFlagRequired("text")
_ = cmd.MarkFlagRequired("chat-id")
_ = cmd.MarkFlagRequired("text")
}
2 changes: 1 addition & 1 deletion service/cli/internal/app/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

type TokenManager interface {
Load()
Load() error
Save() error
SetTokens(accessToken, refreshToken string) error
AccessToken() string
Expand Down
23 changes: 16 additions & 7 deletions service/cli/internal/manager/token_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,25 @@ func NewFileTokenManager(filePath string) *FileTokenManager {
}
}

func (tm *FileTokenManager) Load() {
func (tm *FileTokenManager) Load() error {
var e error
tm.once.Do(func() {
tm.mu.Lock()

defer tm.mu.Unlock()

file, _ := os.Open(tm.filePath)
file, err := os.Open(tm.filePath)
e = err

defer file.Close()
defer func() {
_ = file.Close()
}()

json.NewDecoder(file).Decode(&tm.token)
err = json.NewDecoder(file).Decode(&tm.token)
e = err
})

return e
}

func (tm *FileTokenManager) Save() error {
Expand All @@ -55,7 +62,9 @@ func (tm *FileTokenManager) Save() error {
return err
}

defer file.Close()
defer func() {
_ = file.Close()
}()

err = json.NewEncoder(file).Encode(&tm.token)

Expand Down Expand Up @@ -99,8 +108,8 @@ func (tm *FileTokenManager) ensureDirExists() error {

if _, err := os.Stat(dir); os.IsNotExist(err) {

err := os.MkdirAll(dir, 0755)
err := os.MkdirAll(dir, 0750)

if err != nil {
return err
}
Expand Down

0 comments on commit 8513c00

Please sign in to comment.