mirror of
https://github.com/goravel/goravel.git
synced 2025-09-26 20:51:19 +08:00
1. Add facades.Grpc;
2. Add facades.Response;
This commit is contained in:
@@ -5,6 +5,8 @@ APP_DEBUG=true
|
|||||||
APP_URL=http://localhost
|
APP_URL=http://localhost
|
||||||
APP_HOST=127.0.0.1:3000
|
APP_HOST=127.0.0.1:3000
|
||||||
|
|
||||||
|
GRPC_HOST=
|
||||||
|
|
||||||
LOG_CHANNEL=stack
|
LOG_CHANNEL=stack
|
||||||
|
|
||||||
DB_CONNECTION=mysql
|
DB_CONNECTION=mysql
|
||||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,4 +1,3 @@
|
|||||||
.idea
|
.idea
|
||||||
.env
|
.env
|
||||||
/storage
|
|
||||||
go.sum
|
go.sum
|
0
app/grpc/controllers/.gitignore
vendored
Normal file
0
app/grpc/controllers/.gitignore
vendored
Normal file
@@ -2,13 +2,14 @@ package controllers
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/goravel/framework/support/facades"
|
||||||
)
|
)
|
||||||
|
|
||||||
type UserController struct {
|
type UserController struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (user UserController) Show(c *gin.Context) {
|
func (r UserController) Show(ctx *gin.Context) {
|
||||||
c.JSON(200, gin.H{
|
facades.Response.Success(ctx, gin.H{
|
||||||
"message": "show",
|
"Hello": "Goravel",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@@ -2,26 +2,26 @@ package middleware
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"net/http"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func Cors() gin.HandlerFunc {
|
func Cors() gin.HandlerFunc {
|
||||||
return func(c *gin.Context) {
|
return func(ctx *gin.Context) {
|
||||||
method := c.Request.Method
|
method := ctx.Request.Method
|
||||||
origin := c.Request.Header.Get("Origin")
|
origin := ctx.Request.Header.Get("Origin")
|
||||||
if origin != "" {
|
if origin != "" {
|
||||||
c.Writer.Header().Set("Access-Control-Allow-Origin", "*")
|
ctx.Writer.Header().Set("Access-Control-Allow-Origin", "*")
|
||||||
c.Header("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE,UPDATE")
|
ctx.Writer.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE, UPDATE")
|
||||||
c.Header("Access-Control-Allow-Headers", "Authorization, Content-Length, X-CSRF-Token, Token,session")
|
ctx.Writer.Header().Set("Access-Control-Allow-Headers", "*")
|
||||||
c.Header("Access-Control-Expose-Headers", "Content-Length, Access-Control-Allow-Origin, Access-Control-Allow-Headers")
|
ctx.Writer.Header().Set("Access-Control-Expose-Headers", "Content-Length, Access-Control-Allow-Origin, Access-Control-Allow-Headers, Authorization")
|
||||||
c.Header("Access-Control-Max-Age", "172800")
|
ctx.Writer.Header().Set("Access-Control-Max-Age", "172800")
|
||||||
c.Header("Access-Control-Allow-Credentials", "true")
|
ctx.Writer.Header().Set("Access-Control-Allow-Credentials", "true")
|
||||||
}
|
}
|
||||||
|
|
||||||
if method == "OPTIONS" {
|
if method == "OPTIONS" {
|
||||||
c.JSON(http.StatusOK, "ok!")
|
ctx.AbortWithStatus(204)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Next()
|
ctx.Next()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
12
app/providers/grpc_service_provider.go
Normal file
12
app/providers/grpc_service_provider.go
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
package providers
|
||||||
|
|
||||||
|
type GrpcServiceProvider struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (router *GrpcServiceProvider) Boot() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (router *GrpcServiceProvider) Register() {
|
||||||
|
|
||||||
|
}
|
@@ -5,6 +5,7 @@ import (
|
|||||||
"github.com/goravel/framework/console"
|
"github.com/goravel/framework/console"
|
||||||
"github.com/goravel/framework/database"
|
"github.com/goravel/framework/database"
|
||||||
foundationProviders "github.com/goravel/framework/foundation/providers"
|
foundationProviders "github.com/goravel/framework/foundation/providers"
|
||||||
|
"github.com/goravel/framework/http"
|
||||||
"github.com/goravel/framework/log"
|
"github.com/goravel/framework/log"
|
||||||
"github.com/goravel/framework/route"
|
"github.com/goravel/framework/route"
|
||||||
"github.com/goravel/framework/support"
|
"github.com/goravel/framework/support"
|
||||||
@@ -44,6 +45,8 @@ func init() {
|
|||||||
//Application host, http server listening address.
|
//Application host, http server listening address.
|
||||||
"host": config.Env("APP_HOST", "127.0.0.1:3000"),
|
"host": config.Env("APP_HOST", "127.0.0.1:3000"),
|
||||||
|
|
||||||
|
"grpc_host": config.Env("GRPC_HOST", ""),
|
||||||
|
|
||||||
//Autoloaded service providers
|
//Autoloaded service providers
|
||||||
//The service providers listed here will be automatically loaded on the
|
//The service providers listed here will be automatically loaded on the
|
||||||
//request to your application. Feel free to add your own services to
|
//request to your application. Feel free to add your own services to
|
||||||
@@ -53,10 +56,12 @@ func init() {
|
|||||||
&console.ServiceProvider{},
|
&console.ServiceProvider{},
|
||||||
&database.ServiceProvider{},
|
&database.ServiceProvider{},
|
||||||
&cache.ServiceProvider{},
|
&cache.ServiceProvider{},
|
||||||
|
&http.ServiceProvider{},
|
||||||
&foundationProviders.ArtisanServiceProvider{},
|
&foundationProviders.ArtisanServiceProvider{},
|
||||||
&route.ServiceProvider{},
|
&route.ServiceProvider{},
|
||||||
&providers.AppServiceProvider{},
|
&providers.AppServiceProvider{},
|
||||||
&providers.RouteServiceProvider{},
|
&providers.RouteServiceProvider{},
|
||||||
|
&providers.GrpcServiceProvider{},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
5
go.mod
5
go.mod
@@ -4,7 +4,7 @@ go 1.17
|
|||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/gin-gonic/gin v1.7.3
|
github.com/gin-gonic/gin v1.7.3
|
||||||
github.com/goravel/framework v0.2.3
|
github.com/goravel/framework v0.3.1
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
@@ -50,8 +50,11 @@ require (
|
|||||||
github.com/urfave/cli/v2 v2.3.0 // indirect
|
github.com/urfave/cli/v2 v2.3.0 // indirect
|
||||||
go.uber.org/atomic v1.9.0 // indirect
|
go.uber.org/atomic v1.9.0 // indirect
|
||||||
golang.org/x/crypto v0.0.0-20211117183948-ae814b36b871 // indirect
|
golang.org/x/crypto v0.0.0-20211117183948-ae814b36b871 // indirect
|
||||||
|
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 // indirect
|
||||||
golang.org/x/sys v0.0.0-20211214234402-4825e8c3871d // indirect
|
golang.org/x/sys v0.0.0-20211214234402-4825e8c3871d // indirect
|
||||||
golang.org/x/text v0.3.7 // indirect
|
golang.org/x/text v0.3.7 // indirect
|
||||||
|
google.golang.org/genproto v0.0.0-20211013025323-ce878158c4d4 // indirect
|
||||||
|
google.golang.org/grpc v1.43.0 // indirect
|
||||||
google.golang.org/protobuf v1.27.1 // indirect
|
google.golang.org/protobuf v1.27.1 // indirect
|
||||||
gopkg.in/ini.v1 v1.64.0 // indirect
|
gopkg.in/ini.v1 v1.64.0 // indirect
|
||||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||||
|
@@ -9,9 +9,9 @@ import (
|
|||||||
func Web() {
|
func Web() {
|
||||||
facades.Route.GET("/", func(c *gin.Context) {
|
facades.Route.GET("/", func(c *gin.Context) {
|
||||||
c.JSON(200, gin.H{
|
c.JSON(200, gin.H{
|
||||||
"message": "pong",
|
"Hello": "Goravel",
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
facades.Route.GET("/users", controllers.UserController{}.Show)
|
facades.Route.GET("/user", controllers.UserController{}.Show)
|
||||||
}
|
}
|
||||||
|
2
storage/logs/.gitignore
vendored
2
storage/logs/.gitignore
vendored
@@ -0,0 +1,2 @@
|
|||||||
|
*
|
||||||
|
!.gitignore
|
2
storage/temp/.gitignore
vendored
Normal file
2
storage/temp/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
*
|
||||||
|
!.gitignore
|
Reference in New Issue
Block a user