-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
138 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package config | ||
|
||
type Config struct { | ||
Listener Listener `yaml:"listener"` | ||
} | ||
|
||
type Listener struct { | ||
Address string `yaml:"address"` | ||
Port int `yaml:"port"` | ||
} | ||
|
||
type ConfigContextKey struct { | ||
Address string | ||
Port int | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package config | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"path/filepath" | ||
|
||
"gopkg.in/yaml.v3" | ||
) | ||
|
||
const cfgPath = "internal/config/config.yml" | ||
|
||
func GetConfigFromContext(ctx context.Context) *Config { | ||
value, ok := ctx.Value(ConfigContextKey{}).(*Config) | ||
if !ok { | ||
return nil | ||
} | ||
|
||
return value | ||
} | ||
|
||
func CreateConfigContext() (context.Context, error) { | ||
ctx := context.Background() | ||
config, err := readConf() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return context.WithValue(ctx, ConfigContextKey{}, config), nil | ||
} | ||
|
||
func readConf() (*Config, error) { | ||
cfg := &Config{} | ||
|
||
filename, _ := filepath.Abs(cfgPath) | ||
data, err := os.ReadFile(filename) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
err = yaml.Unmarshal(data, cfg) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return cfg, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,14 @@ | ||
package errors | ||
|
||
import "errors" | ||
|
||
var ( | ||
ErrInvalidEmailCode = "invalid_email" | ||
ErrInvalidEmailText = "email is incorrect" | ||
ErrInvalidEmailText = errors.New("email is incorrect") | ||
ErrInvalidPasswordCode = "invalid_password" | ||
ErrInvalidPasswordText = "password is too short. The minimal len is 8" | ||
ErrInvalidPasswordText = errors.New("password is too short. The minimal len is 8") | ||
ErrInvalidSexCode = "invalid_sex" | ||
ErrInvalidSexText = "only male or female allowed" | ||
ErrInvalidSexText = errors.New("only male or female allowed") | ||
ErrInvalidBirthdateCode = "invalid_birthdate" | ||
ErrInvalidBirthdateText = "bithdate should be before current time" | ||
ErrInvalidBirthdateText = errors.New("bithdate should be before current time") | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 9 additions & 3 deletions
12
validation-service/internal/app/service/validation/validation.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,19 @@ | ||
package validation | ||
|
||
import ( | ||
"context" | ||
|
||
api "github.com/go-park-mail-ru/2024_2_GOATS/validation-service/internal/app/api/validation" | ||
) | ||
|
||
var _ api.ValidationService = (*serv)(nil) | ||
|
||
type serv struct{} | ||
type serv struct{ | ||
ctx context.Context | ||
} | ||
|
||
func NewService() *serv { | ||
return &serv{} | ||
func NewService(ctx context.Context) *serv { | ||
return &serv{ | ||
ctx: ctx, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
listener: | ||
address: localhost | ||
port: 5050 |
Oops, something went wrong.