-
Notifications
You must be signed in to change notification settings - Fork 49
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
1 parent
effad94
commit 6d99ce0
Showing
12 changed files
with
128 additions
and
120 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,6 +1,12 @@ | ||
REDIS_HOST=localhost | ||
REDIS_PORT=6379 | ||
|
||
POSTGRES_HOST=localhost | ||
POSTGRES_PORT=5432 | ||
POSTGRES_USER=postgres | ||
POSTGRES_PASSWORD=postgres | ||
POSTGRES_DATABASE=postgres | ||
|
||
BACKEND_HOST=localhost | ||
BACKEND_PORT=8082 | ||
CONSUMER_PORT=8081 |
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
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,99 +1,94 @@ | ||
package config | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"os" | ||
"strconv" | ||
) | ||
|
||
type BackendScriptsConfig struct { | ||
PlacePixelDevnet string `json:"place_pixel_devnet"` | ||
PlaceExtraPixelsDevnet string `json:"place_extra_pixels_devnet"` | ||
AddTemplateDevnet string `json:"add_template_devnet"` | ||
ClaimTodayQuestDevnet string `json:"claim_today_quest_devnet"` | ||
MintNFTDevnet string `json:"mint_nft_devnet"` | ||
LikeNFTDevnet string `json:"like_nft_devnet"` | ||
UnlikeNFTDevnet string `json:"unlike_nft_devnet"` | ||
VoteColorDevnet string `json:"vote_color_devnet"` | ||
NewUsernameDevnet string `json:"new_username_devnet"` | ||
ChangeUsernameDevnet string `json:"change_username_devnet"` | ||
IncreaseDayDevnet string `json:"increase_day_devnet"` | ||
JoinChainFactionDevnet string `json:"join_chain_faction_devnet"` | ||
JoinFactionDevnet string `json:"join_faction_devnet"` | ||
LeaveFactionDevnet string `json:"leave_faction_devnet"` | ||
AddFactionTemplateDevnet string `json:"add_faction_template_devnet"` | ||
RemoveFactionTemplateDevnet string `json:"remove_faction_template_devnet"` | ||
PlacePixelDevnet string | ||
PlaceExtraPixelsDevnet string | ||
AddTemplateDevnet string | ||
ClaimTodayQuestDevnet string | ||
MintNFTDevnet string | ||
LikeNFTDevnet string | ||
UnlikeNFTDevnet string | ||
VoteColorDevnet string | ||
NewUsernameDevnet string | ||
ChangeUsernameDevnet string | ||
IncreaseDayDevnet string | ||
JoinChainFactionDevnet string | ||
JoinFactionDevnet string | ||
LeaveFactionDevnet string | ||
AddFactionTemplateDevnet string | ||
RemoveFactionTemplateDevnet string | ||
} | ||
|
||
type WebSocketConfig struct { | ||
ReadBufferSize int `json:"read_buffer_size"` | ||
WriteBufferSize int `json:"write_buffer_size"` | ||
ReadBufferSize int | ||
WriteBufferSize int | ||
} | ||
|
||
type HttpConfig struct { | ||
AllowOrigin []string `json:"allow_origin"` | ||
AllowMethods []string `json:"allow_methods"` | ||
AllowHeaders []string `json:"allow_headers"` | ||
AllowOrigin []string | ||
AllowMethods []string | ||
AllowHeaders []string | ||
} | ||
|
||
type BackendConfig struct { | ||
Host string `json:"host"` | ||
Port int `json:"port"` | ||
ConsumerPort int `json:"consumer_port"` | ||
Scripts BackendScriptsConfig `json:"scripts"` | ||
Production bool `json:"production"` | ||
WebSocket WebSocketConfig `json:"websocket"` | ||
Http HttpConfig `json:"http_config"` | ||
Host string | ||
Port int | ||
ConsumerPort int | ||
Scripts BackendScriptsConfig | ||
Production bool | ||
WebSocket WebSocketConfig | ||
Http HttpConfig | ||
} | ||
|
||
var DefaultBackendConfig = BackendConfig{ | ||
Host: "localhost", | ||
Port: 8080, | ||
ConsumerPort: 8081, | ||
Scripts: BackendScriptsConfig{ | ||
PlacePixelDevnet: "../scripts/place_pixel.sh", | ||
PlaceExtraPixelsDevnet: "../scripts/place_extra_pixels.sh", | ||
AddTemplateDevnet: "../scripts/add_template.sh", | ||
ClaimTodayQuestDevnet: "../scripts/claim_today_quest.sh", | ||
MintNFTDevnet: "../scripts/mint_nft.sh", | ||
LikeNFTDevnet: "../scripts/like_nft.sh", | ||
UnlikeNFTDevnet: "../scripts/unlike_nft.sh", | ||
VoteColorDevnet: "../scripts/vote_color.sh", | ||
NewUsernameDevnet: "../scripts/new_username.sh", | ||
ChangeUsernameDevnet: "../scripts/change_username.sh", | ||
IncreaseDayDevnet: "../scripts/increase_day_index.sh", | ||
JoinChainFactionDevnet: "../scripts/join_chain_faction.sh", | ||
JoinFactionDevnet: "../scripts/join_faction.sh", | ||
LeaveFactionDevnet: "../scripts/leave_faction.sh", | ||
AddFactionTemplateDevnet: "../scripts/add_faction_template.sh", | ||
RemoveFactionTemplateDevnet: "../scripts/remove_faction_template.sh", | ||
}, | ||
Production: false, | ||
WebSocket: WebSocketConfig{ | ||
ReadBufferSize: 1024, | ||
WriteBufferSize: 1024, | ||
}, | ||
Http: HttpConfig{ | ||
AllowOrigin: []string{"*"}, | ||
AllowMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"}, | ||
AllowHeaders: []string{"Content-Type"}, | ||
}, | ||
} | ||
|
||
var DefaultBackendConfigPath = "./configs/backend.config.json" | ||
|
||
func LoadBackendConfig(backendConfigPath string) (*BackendConfig, error) { | ||
file, err := os.Open(backendConfigPath) | ||
func LoadBackendConfig() (*BackendConfig, error) { | ||
backendPort, err := strconv.Atoi(os.Getenv("BACKEND_PORT")) | ||
if err != nil { | ||
return nil, err | ||
return nil, fmt.Errorf("invalid BACKEND_PORT: %v", err) | ||
} | ||
defer file.Close() | ||
|
||
decoder := json.NewDecoder(file) | ||
config := BackendConfig{} | ||
err = decoder.Decode(&config) | ||
consumerPort, err := strconv.Atoi(os.Getenv("CONSUMER_PORT")) | ||
if err != nil { | ||
return nil, err | ||
return nil, fmt.Errorf("invalid BACKEND_PORT: %v", err) | ||
} | ||
|
||
config := BackendConfig{ | ||
Host: os.Getenv("BACKEND_HOST"), | ||
Port: backendPort, | ||
ConsumerPort: consumerPort, | ||
Scripts: BackendScriptsConfig{ | ||
PlacePixelDevnet: "../scripts/place_pixel.sh", | ||
PlaceExtraPixelsDevnet: "../scripts/place_extra_pixels.sh", | ||
AddTemplateDevnet: "../scripts/add_template.sh", | ||
ClaimTodayQuestDevnet: "../scripts/claim_today_quest.sh", | ||
MintNFTDevnet: "../scripts/mint_nft.sh", | ||
LikeNFTDevnet: "../scripts/like_nft.sh", | ||
UnlikeNFTDevnet: "../scripts/unlike_nft.sh", | ||
VoteColorDevnet: "../scripts/vote_color.sh", | ||
NewUsernameDevnet: "../scripts/new_username.sh", | ||
ChangeUsernameDevnet: "../scripts/change_username.sh", | ||
IncreaseDayDevnet: "../scripts/increase_day_index.sh", | ||
JoinChainFactionDevnet: "../scripts/join_chain_faction.sh", | ||
JoinFactionDevnet: "../scripts/join_faction.sh", | ||
LeaveFactionDevnet: "../scripts/leave_faction.sh", | ||
AddFactionTemplateDevnet: "../scripts/add_faction_template.sh", | ||
RemoveFactionTemplateDevnet: "../scripts/remove_faction_template.sh", | ||
}, | ||
Production: false, | ||
WebSocket: WebSocketConfig{ | ||
ReadBufferSize: 1024, | ||
WriteBufferSize: 1024, | ||
}, | ||
Http: HttpConfig{ | ||
AllowOrigin: []string{"*"}, | ||
AllowMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"}, | ||
AllowHeaders: []string{"Content-Type"}, | ||
}, | ||
} | ||
return &config, nil | ||
} |
Oops, something went wrong.