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

Commitacef7b8

Browse files
committed
updated
1 parentcdcd072 commitacef7b8

File tree

9 files changed

+350
-79
lines changed

9 files changed

+350
-79
lines changed

‎cmd/server/main.go

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ import (
1010
"github.com/gin-contrib/cors"
1111
"github.com/gin-gonic/gin"
1212
"github.com/wpcodevo/golang-postgresql-api/config"
13-
"github.com/wpcodevo/golang-postgresql-api/controllers"
1413
dbConn"github.com/wpcodevo/golang-postgresql-api/db/sqlc"
15-
"github.com/wpcodevo/golang-postgresql-api/routes"
1614

1715
_"github.com/lib/pq"
1816
)
@@ -21,11 +19,6 @@ var (
2119
server*gin.Engine
2220
db*dbConn.Queries
2321
ctx context.Context
24-
25-
AuthController controllers.AuthController
26-
UserController controllers.UserController
27-
AuthRoutes routes.AuthRoutes
28-
UserRoutes routes.UserRoutes
2922
)
3023

3124
funcinit() {
@@ -45,11 +38,6 @@ func init() {
4538

4639
fmt.Println("PostgreSQL connected successfully...")
4740

48-
AuthController=*controllers.NewAuthController(db,ctx)
49-
UserController=controllers.NewUserController(db,ctx)
50-
AuthRoutes=routes.NewAuthRoutes(AuthController,db)
51-
UserRoutes=routes.NewUserRoutes(UserController,db)
52-
5341
server=gin.Default()
5442
}
5543

@@ -72,11 +60,8 @@ func main() {
7260
ctx.JSON(http.StatusOK, gin.H{"status":"success","message":"Welcome to Golang with PostgreSQL"})
7361
})
7462

75-
AuthRoutes.AuthRoute(router)
76-
UserRoutes.UserRoute(router)
77-
7863
server.NoRoute(func(ctx*gin.Context) {
7964
ctx.JSON(http.StatusNotFound, gin.H{"status":"fail","message":fmt.Sprintf("Route %s not found",ctx.Request.URL)})
8065
})
81-
log.Fatal(server.Run(":"+config.Port))
66+
log.Fatal(server.Run(":"+config.ServerPort))
8267
}

‎config/default.go

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,15 @@
11
package config
22

33
import (
4-
"time"
5-
64
"github.com/spf13/viper"
75
)
86

97
typeConfigstruct {
108
PostgreDriverstring`mapstructure:"POSTGRES_DRIVER"`
119
PostgresSourcestring`mapstructure:"POSTGRES_SOURCE"`
12-
13-
Portstring`mapstructure:"PORT"`
14-
15-
Originstring`mapstructure:"ORIGIN"`
16-
17-
AccessTokenPrivateKeystring`mapstructure:"ACCESS_TOKEN_PRIVATE_KEY"`
18-
AccessTokenPublicKeystring`mapstructure:"ACCESS_TOKEN_PUBLIC_KEY"`
19-
RefreshTokenPrivateKeystring`mapstructure:"REFRESH_TOKEN_PRIVATE_KEY"`
20-
RefreshTokenPublicKeystring`mapstructure:"REFRESH_TOKEN_PUBLIC_KEY"`
21-
AccessTokenExpiresIn time.Duration`mapstructure:"ACCESS_TOKEN_EXPIRED_IN"`
22-
RefreshTokenExpiresIn time.Duration`mapstructure:"REFRESH_TOKEN_EXPIRED_IN"`
23-
AccessTokenMaxAgeint`mapstructure:"ACCESS_TOKEN_MAXAGE"`
24-
RefreshTokenMaxAgeint`mapstructure:"REFRESH_TOKEN_MAXAGE"`
10+
ServerPortstring`mapstructure:"SERVER_PORT"`
11+
ClientPortstring`mapstructure:"CLIENT_PORT"`
12+
Originstring`mapstructure:"ORIGIN"`
2513
}
2614

2715
funcLoadConfig(pathstring) (configConfig,errerror) {
Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1 @@
1-
CREATE TABLE
2-
"posts" (
3-
"id" UUIDNOT NULL DEFAULT (uuid_generate_v4()),
4-
"title"VARCHARNOT NULL,
5-
"category"VARCHARNOT NULL,
6-
"content"VARCHARNOT NULL,
7-
"image"VARCHARNOT NULL,
8-
"created_at"TIMESTAMP(3)NOT NULL DEFAULTCURRENT_TIMESTAMP,
9-
"updated_at"TIMESTAMP(3)NOT NULL,
10-
CONSTRAINT"posts_pkey"PRIMARY KEY ("id")
11-
);
12-
13-
CREATEUNIQUE INDEX "users_email_key"ON"users"("email");
1+
DROPTABLE IF EXISTS posts;
Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,13 @@
1-
DROPTABLE posts;
1+
CREATE TABLE
2+
"posts" (
3+
"id" UUIDNOT NULL DEFAULT (uuid_generate_v4()),
4+
"title"VARCHARNOT NULL,
5+
"category"VARCHARNOT NULL,
6+
"content"VARCHARNOT NULL,
7+
"image"VARCHARNOT NULL,
8+
"created_at"TIMESTAMP(3)NOT NULL DEFAULTCURRENT_TIMESTAMP,
9+
"updated_at"TIMESTAMP(3)NOT NULL,
10+
CONSTRAINT"posts_pkey"PRIMARY KEY ("id")
11+
);
12+
13+
CREATEUNIQUE INDEX "posts_title_key"ON"posts"("title");

‎db/sqlc/db.go

Lines changed: 128 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎db/sqlc/models.go

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp