Skip to content

Commit

Permalink
env: use only http port
Browse files Browse the repository at this point in the history
  • Loading branch information
labasubagia committed Sep 13, 2023
1 parent b166c96 commit a80b015
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
POSTGRES_SOURCE=postgres://postgres:postgres@0.0.0.0:5432/realworld?sslmode=disable
POSTGRES_MIGRATION_URL=file://internal/adapter/repository/sql/db/migration
MONGO_SOURCE=mongodb://root:root@0.0.0.0:27017/realworld?authSource=admin
HTTP_SERVER_ADDRESS=0.0.0.0:5000
HTTP_SERVER_PORT=5000
TOKEN_SYMMETRIC_KEY=12345678901234567890123456789012
2 changes: 1 addition & 1 deletion .env.test
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
POSTGRES_SOURCE=postgres://postgres:postgres@0.0.0.0:5432/realworld?sslmode=disable
POSTGRES_MIGRATION_URL=file://../../../internal/adapter/repository/sql/db/migration
MONGO_SOURCE=mongodb://root:root@0.0.0.0:27017/realworld?authSource=admin
HTTP_SERVER_ADDRESS=0.0.0.0:5000
HTTP_SERVER_PORT=5000
TOKEN_SYMMETRIC_KEY=12345678901234567890123456789012
4 changes: 2 additions & 2 deletions cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func init() {

rootCmd.AddCommand(serverCmd)
serverCmd.Flags().StringP("database", "d", repository.DefaultRepoKey, fmt.Sprintf("select database in (%s)", dbOptStr))
serverCmd.Flags().IntP("port", "p", 5000, fmt.Sprint("server port "))
serverCmd.Flags().IntP("port", "p", config.HTTPServerPort, "server port")
}

var serverCmd = &cobra.Command{
Expand All @@ -33,7 +33,7 @@ var serverCmd = &cobra.Command{
if err != nil {
log.Fatal("failed get port flag", err)
}
config.HTTPServerAddress = fmt.Sprintf("0.0.0.0:%d", port)
config.HTTPServerPort = port

dbType, err := cmd.Flags().GetString("database")
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion internal/adapter/handler/restful/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package restful

import (
"context"
"fmt"
"log"
"net/http"
"os"
Expand Down Expand Up @@ -78,7 +79,7 @@ func (server *Server) setupRouter() {

func (server *Server) Start() error {
srv := &http.Server{
Addr: server.config.HTTPServerAddress,
Addr: fmt.Sprintf(":%d", server.config.HTTPServerPort),
Handler: server.router,
}

Expand Down
9 changes: 6 additions & 3 deletions internal/core/util/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ import (
type Config struct {
PostgresSource string `mapstructure:"POSTGRES_SOURCE"`
PostgresMigrationURL string `mapstructure:"POSTGRES_MIGRATION_URL"`
MongoSource string `mapstructure:"MONGO_SOURCE"`
HTTPServerAddress string `mapstructure:"HTTP_SERVER_ADDRESS"`
TokenSymmetricKey string `mapstructure:"TOKEN_SYMMETRIC_KEY"`

MongoSource string `mapstructure:"MONGO_SOURCE"`

HTTPServerPort int `mapstructure:"HTTP_SERVER_PORT"`

TokenSymmetricKey string `mapstructure:"TOKEN_SYMMETRIC_KEY"`

TestRepo string `mapstructure:"TEST_REPO"`
}
Expand Down

0 comments on commit a80b015

Please sign in to comment.