Skip to content

Commit

Permalink
:product branch connection established and basic functionalities added
Browse files Browse the repository at this point in the history
  • Loading branch information
abhinandpn committed Nov 27, 2023
1 parent 81e0eee commit eae7293
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 24 deletions.
44 changes: 44 additions & 0 deletions product-services/.air.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
root = "."
testdata_dir = "testdata"
tmp_dir = "tmp"

[build]
args_bin = []
bin = "cmd/api/tmp/api.exe"
cmd = "go build -o ./cmd/api/tmp/api.exe ./cmd/api/main.go"
delay = 0
exclude_dir = ["assets", "tmp", "vendor", "testdata"]
exclude_file = []
exclude_regex = ["_test.go"]
exclude_unchanged = false
follow_symlink = false
full_bin = ""
include_dir = []
include_ext = ["go", "tpl", "tmpl", "html"]
include_file = []
kill_delay = "0s"
log = "build-errors.log"
poll = false
poll_interval = 0
rerun = false
rerun_delay = 500
send_interrupt = false
stop_on_error = false

[color]
app = ""
build = "yellow"
main = "magenta"
runner = "green"
watcher = "cyan"

[log]
main_only = false
time = false

[misc]
clean_on_exit = false

[screen]
clear_on_rebuild = false
keep_scroll = true
2 changes: 1 addition & 1 deletion product-services/.env
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

DB_HOST=localhost
DB_USER=admin
DB_NAME=footex
DB_NAME=microsample
DB_PORT=5432
DB_PASSWORD=admin
2 changes: 1 addition & 1 deletion product-services/cmd/api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

func main() {

cfg, confErr := config.LoadCOnfig()
cfg, confErr := config.LoadConfig()

if confErr != nil {
log.Fatal("cannot load config: ", confErr)
Expand Down
Binary file added product-services/cmd/api/tmp/api.exe
Binary file not shown.
15 changes: 15 additions & 0 deletions product-services/pkg/api/routes/product.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,19 @@ import (
func ProductRoute(api *gin.RouterGroup,
ProductHandler handlerinterfaces.ProductHandler) {

product := api.Group("/product")
{
// Product Basic
product.POST("/add", ProductHandler.AddProduct) // Product Adding
product.PATCH("/:id", ProductHandler.UpdateProduct) // Product Update
product.DELETE("/:id", ProductHandler.DeteleProduct) // Product Delete
product.GET("/id", ProductHandler.GetProductById) // Product GetById

// Listing
product.GET("/all", ProductHandler.ListFullProducts) // Full Products Listing
product.GET("/category/:name") // Products Listing By category4
product.GET("/brand/:name") // Producr Listign By name
product.GET("/subcategory/:name") // Product Listign By sub-category
}

}
2 changes: 1 addition & 1 deletion product-services/pkg/api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func NewServerHTTP(ProductHandler handlerinterfaces.ProductHandler) *ServerHTTP
// For Swagger
// Engine.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerfiles.Handler))

routes.ProductRoute(Engine.Group("/admin"),
routes.ProductRoute(Engine.Group("/product"),
ProductHandler,
)
return &ServerHTTP{engine: Engine}
Expand Down
29 changes: 9 additions & 20 deletions product-services/pkg/config/config.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package config

import (
"os"

"github.com/go-playground/validator"
"github.com/spf13/viper"
)
Expand All @@ -19,28 +17,20 @@ var envs = []string{
"DB_HOST", "DB_NAME", "DB_USER", "DB_PORT", "DB_PASSWORD", // Database
}

var config Config // for create instance

func LoadCOnfig() (Config, error) {

v := viper.New()
var config Config // create instence of config

// Get the current working directory
wd, err := os.Getwd()
if err != nil {
return config, err
}
// func to get env variable and store it on struct Config and retuen it with error as nil or error
func LoadConfig() (Config, error) {

//Viper setup
v.AddConfigPath(wd)
v.SetConfigFile(".env")
v.ReadInConfig() // for read config
// vipen setup
viper.AddConfigPath("./") // add config path
viper.SetConfigFile(".env") //setup file name to viper
viper.ReadInConfig() // read .env file

v.SetEnvPrefix("product-services")
v.AutomaticEnv()
// range through the envNames and take each envName and bind that env variable to viper

for _, env := range envs {
if err := v.BindEnv(env); err != nil {
if err := viper.BindEnv(env); err != nil {
return config, err // error handling
}
}
Expand All @@ -58,7 +48,6 @@ func LoadCOnfig() (Config, error) {
}

//successfully loaded the env values into struct config

return config, nil
}

Expand Down
1 change: 0 additions & 1 deletion product-services/pkg/models/product.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@ type Product struct {
ProductName string
Discription string
Price float64
Quantity int
Category string
}
1 change: 1 addition & 0 deletions product-services/tmp/build-errors.log
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exit status 1exit status 1exit status 1exit status 1exit status 1exit status 1

0 comments on commit eae7293

Please sign in to comment.