-
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
19 changed files
with
148 additions
and
63 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
/validation-service/bin/ | ||
/validation-service/.env |
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,21 +1,17 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"log" | ||
|
||
"github.com/go-park-mail-ru/2024_2_GOATS/validation-service/internal/app" | ||
) | ||
|
||
const serverPort = 5050 | ||
|
||
func main() { | ||
ctx := context.Background() | ||
a, err := app.New(ctx, serverPort) | ||
a, ctx, err := app.New() | ||
|
||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
a.Run() | ||
a.Run(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,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,53 @@ | ||
package config | ||
|
||
import ( | ||
"context" | ||
"log" | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/joho/godotenv" | ||
"gopkg.in/yaml.v3" | ||
) | ||
|
||
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) { | ||
err := godotenv.Load() | ||
|
||
if err != nil { | ||
log.Fatalf("Error loading .env file", err) | ||
} | ||
|
||
cfg := &Config{} | ||
|
||
filename, _ := filepath.Abs(os.Getenv("CFG_PATH")) | ||
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
Oops, something went wrong.