Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9da615e

Browse files
ziddah edemziddah edem
ziddah edem
authored and
ziddah edem
committed
updated
1 parente8b71b5 commit9da615e

File tree

14 files changed

+1150
-1150
lines changed

14 files changed

+1150
-1150
lines changed

‎.air.toml

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
1-
root ="."
2-
testdata_dir ="testdata"
3-
tmp_dir ="tmp"
4-
5-
[build]
6-
bin ="./tmp/main"
7-
cmd ="go build -o ./tmp/main ./cmd/server/main.go"
8-
delay =1000
9-
exclude_dir = ["assets","tmp","vendor","testdata"]
10-
exclude_file = []
11-
exclude_regex = ["_test.go"]
12-
exclude_unchanged =false
13-
follow_symlink =false
14-
full_bin =""
15-
include_dir = []
16-
include_ext = ["go","tpl","tmpl","html"]
17-
kill_delay ="0s"
18-
log ="build-errors.log"
19-
send_interrupt =false
20-
stop_on_error =true
21-
22-
[color]
23-
app =""
24-
build ="yellow"
25-
main ="magenta"
26-
runner ="green"
27-
watcher ="cyan"
28-
29-
[log]
30-
time =false
31-
32-
[misc]
33-
clean_on_exit =false
34-
35-
[screen]
36-
clear_on_rebuild =false
1+
root ="."
2+
testdata_dir ="testdata"
3+
tmp_dir ="tmp"
4+
5+
[build]
6+
bin ="./tmp/main"
7+
cmd ="go build -o ./tmp/main ./cmd/server/main.go"
8+
delay =1000
9+
exclude_dir = ["assets","tmp","vendor","testdata"]
10+
exclude_file = []
11+
exclude_regex = ["_test.go"]
12+
exclude_unchanged =false
13+
follow_symlink =false
14+
full_bin =""
15+
include_dir = []
16+
include_ext = ["go","tpl","tmpl","html"]
17+
kill_delay ="0s"
18+
log ="build-errors.log"
19+
send_interrupt =false
20+
stop_on_error =true
21+
22+
[color]
23+
app =""
24+
build ="yellow"
25+
main ="magenta"
26+
runner ="green"
27+
watcher ="cyan"
28+
29+
[log]
30+
time =false
31+
32+
[misc]
33+
clean_on_exit =false
34+
35+
[screen]
36+
clear_on_rebuild =false

‎.gitignore

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
# Binaries for programs and plugins
2-
*.exe
3-
*.exe~
4-
*.dll
5-
*.so
6-
*.dylib
7-
8-
# Test binary, built with `go test -c`
9-
*.test
10-
11-
# Output of the go coverage tool, specifically when used with LiteIDE
12-
*.out
13-
14-
# Dependency directories (remove the comment below to include it)
15-
# vendor/
16-
.DS_Store
17-
TODO.md
18-
logs.txt
19-
.idea/
20-
secret.md
1+
# Binaries for programs and plugins
2+
*.exe
3+
*.exe~
4+
*.dll
5+
*.so
6+
*.dylib
7+
8+
# Test binary, built with `go test -c`
9+
*.test
10+
11+
# Output of the go coverage tool, specifically when used with LiteIDE
12+
*.out
13+
14+
# Dependency directories (remove the comment below to include it)
15+
# vendor/
16+
.DS_Store
17+
TODO.md
18+
logs.txt
19+
.idea/
20+
secret.md
2121
app.env

‎cmd/server/main.go

Lines changed: 63 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,63 @@
1-
package main
2-
3-
import (
4-
"database/sql"
5-
"fmt"
6-
"log"
7-
"net/http"
8-
9-
"github.com/gin-gonic/gin"
10-
"github.com/wpcodevo/golang-postgresql-grpc/config"
11-
"github.com/wpcodevo/golang-postgresql-grpc/controllers"
12-
dbConn"github.com/wpcodevo/golang-postgresql-grpc/db/sqlc"
13-
"github.com/wpcodevo/golang-postgresql-grpc/routes"
14-
15-
_"github.com/lib/pq"
16-
)
17-
18-
var (
19-
server*gin.Engine
20-
db*dbConn.Queries
21-
22-
AuthController controllers.AuthController
23-
AuthRoutes routes.AuthRoutes
24-
)
25-
26-
funcinit() {
27-
config,err:=config.LoadConfig(".")
28-
29-
iferr!=nil {
30-
log.Fatalf("could not load config: %v",err)
31-
}
32-
33-
conn,err:=sql.Open(config.PostgreDriver,config.PostgresSource)
34-
iferr!=nil {
35-
log.Fatalf("could not connect to postgres database: %v",err)
36-
}
37-
38-
db=dbConn.New(conn)
39-
40-
fmt.Println("PostgreSQL connected successfully...")
41-
42-
AuthController=*controllers.NewAuthController(db)
43-
AuthRoutes=routes.NewAuthRoutes(AuthController)
44-
45-
server=gin.Default()
46-
}
47-
48-
funcmain() {
49-
config,err:=config.LoadConfig(".")
50-
51-
iferr!=nil {
52-
log.Fatalf("could not load config: %v",err)
53-
}
54-
55-
router:=server.Group("/api")
56-
57-
router.GET("/healthchecker",func(ctx*gin.Context) {
58-
ctx.JSON(http.StatusOK, gin.H{"status":"success","message":"Welcome to Golang with PostgreSQL"})
59-
})
60-
61-
AuthRoutes.AuthRoute(router)
62-
log.Fatal(server.Run(":"+config.Port))
63-
}
1+
package main
2+
3+
import (
4+
"database/sql"
5+
"fmt"
6+
"log"
7+
"net/http"
8+
9+
"github.com/gin-gonic/gin"
10+
"github.com/wpcodevo/golang-postgresql-grpc/config"
11+
"github.com/wpcodevo/golang-postgresql-grpc/controllers"
12+
dbConn"github.com/wpcodevo/golang-postgresql-grpc/db/sqlc"
13+
"github.com/wpcodevo/golang-postgresql-grpc/routes"
14+
15+
_"github.com/lib/pq"
16+
)
17+
18+
var (
19+
server*gin.Engine
20+
db*dbConn.Queries
21+
22+
AuthController controllers.AuthController
23+
AuthRoutes routes.AuthRoutes
24+
)
25+
26+
funcinit() {
27+
config,err:=config.LoadConfig(".")
28+
29+
iferr!=nil {
30+
log.Fatalf("could not load config: %v",err)
31+
}
32+
33+
conn,err:=sql.Open(config.PostgreDriver,config.PostgresSource)
34+
iferr!=nil {
35+
log.Fatalf("could not connect to postgres database: %v",err)
36+
}
37+
38+
db=dbConn.New(conn)
39+
40+
fmt.Println("PostgreSQL connected successfully...")
41+
42+
AuthController=*controllers.NewAuthController(db)
43+
AuthRoutes=routes.NewAuthRoutes(AuthController)
44+
45+
server=gin.Default()
46+
}
47+
48+
funcmain() {
49+
config,err:=config.LoadConfig(".")
50+
51+
iferr!=nil {
52+
log.Fatalf("could not load config: %v",err)
53+
}
54+
55+
router:=server.Group("/api")
56+
57+
router.GET("/healthchecker",func(ctx*gin.Context) {
58+
ctx.JSON(http.StatusOK, gin.H{"status":"success","message":"Welcome to Golang with PostgreSQL"})
59+
})
60+
61+
AuthRoutes.AuthRoute(router)
62+
log.Fatal(server.Run(":"+config.Port))
63+
}

‎config/default.go

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
1-
package config
2-
3-
import (
4-
"github.com/spf13/viper"
5-
)
6-
7-
typeConfigstruct {
8-
PostgreDriverstring`mapstructure:"POSTGRES_DRIVER"`
9-
PostgresSourcestring`mapstructure:"POSTGRES_SOURCE"`
10-
11-
Portstring`mapstructure:"PORT"`
12-
}
13-
14-
funcLoadConfig(pathstring) (configConfig,errerror) {
15-
viper.AddConfigPath(path)
16-
viper.SetConfigType("env")
17-
viper.SetConfigName("app")
18-
19-
viper.AutomaticEnv()
20-
21-
err=viper.ReadInConfig()
22-
iferr!=nil {
23-
return
24-
}
25-
26-
err=viper.Unmarshal(&config)
27-
return
28-
}
1+
package config
2+
3+
import (
4+
"github.com/spf13/viper"
5+
)
6+
7+
typeConfigstruct {
8+
PostgreDriverstring`mapstructure:"POSTGRES_DRIVER"`
9+
PostgresSourcestring`mapstructure:"POSTGRES_SOURCE"`
10+
11+
Portstring`mapstructure:"PORT"`
12+
}
13+
14+
funcLoadConfig(pathstring) (configConfig,errerror) {
15+
viper.AddConfigPath(path)
16+
viper.SetConfigType("env")
17+
viper.SetConfigName("app")
18+
19+
viper.AutomaticEnv()
20+
21+
err=viper.ReadInConfig()
22+
iferr!=nil {
23+
return
24+
}
25+
26+
err=viper.Unmarshal(&config)
27+
return
28+
}

‎controllers/signup.controller.go

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,48 @@
1-
package controllers
2-
3-
import (
4-
"net/http"
5-
"time"
6-
7-
"github.com/gin-gonic/gin"
8-
db"github.com/wpcodevo/golang-postgresql-grpc/db/sqlc"
9-
"github.com/wpcodevo/golang-postgresql-grpc/utils"
10-
)
11-
12-
typeAuthControllerstruct {
13-
db*db.Queries
14-
}
15-
16-
funcNewAuthController(db*db.Queries)*AuthController {
17-
return&AuthController{db}
18-
}
19-
20-
func (ac*AuthController)SignUpUser(ctx*gin.Context) {
21-
varcredentials*db.User
22-
23-
iferr:=ctx.ShouldBindJSON(&credentials);err!=nil {
24-
ctx.JSON(http.StatusBadRequest,err.Error())
25-
return
26-
}
27-
28-
hashedPassword:=utils.HashPassword(credentials.Password)
29-
30-
args:=&db.CreateUserParams{
31-
Name:credentials.Name,
32-
Email:credentials.Email,
33-
Password:hashedPassword,
34-
Photo:"default.jpeg",
35-
Verified:true,
36-
Role:"user",
37-
UpdatedAt:time.Now(),
38-
}
39-
40-
user,err:=ac.db.CreateUser(ctx,*args)
41-
42-
iferr!=nil {
43-
ctx.JSON(http.StatusBadGateway,err.Error())
44-
return
45-
}
46-
47-
ctx.JSON(http.StatusCreated, gin.H{"status":"success","data": gin.H{"user":user}})
48-
}
1+
package controllers
2+
3+
import (
4+
"net/http"
5+
"time"
6+
7+
"github.com/gin-gonic/gin"
8+
db"github.com/wpcodevo/golang-postgresql-grpc/db/sqlc"
9+
"github.com/wpcodevo/golang-postgresql-grpc/utils"
10+
)
11+
12+
typeAuthControllerstruct {
13+
db*db.Queries
14+
}
15+
16+
funcNewAuthController(db*db.Queries)*AuthController {
17+
return&AuthController{db}
18+
}
19+
20+
func (ac*AuthController)SignUpUser(ctx*gin.Context) {
21+
varcredentials*db.User
22+
23+
iferr:=ctx.ShouldBindJSON(&credentials);err!=nil {
24+
ctx.JSON(http.StatusBadRequest,err.Error())
25+
return
26+
}
27+
28+
hashedPassword:=utils.HashPassword(credentials.Password)
29+
30+
args:=&db.CreateUserParams{
31+
Name:credentials.Name,
32+
Email:credentials.Email,
33+
Password:hashedPassword,
34+
Photo:"default.jpeg",
35+
Verified:true,
36+
Role:"user",
37+
UpdatedAt:time.Now(),
38+
}
39+
40+
user,err:=ac.db.CreateUser(ctx,*args)
41+
42+
iferr!=nil {
43+
ctx.JSON(http.StatusBadGateway,err.Error())
44+
return
45+
}
46+
47+
ctx.JSON(http.StatusCreated, gin.H{"status":"success","data": gin.H{"user":user}})
48+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp