Skip to content

Commit

Permalink
feat: sync latest framework changes (#20)
Browse files Browse the repository at this point in the history
* feat: sync latest framework changes

* feat: add rate limiter example

* fix: lint

* fix: lint

* fix: lint

* fix: lint

* feat: add throttle test

* feat: optimize throttle test

* feat: bump postgres version to 16

* feat: modify port

* fix: test

* fix: test

* optimize test

* optimize test

* optimize test

* optimize test

---------

Co-authored-by: Bowen <[email protected]>
  • Loading branch information
devhaozi and hwbrzzl authored Sep 4, 2024
1 parent e5e9e36 commit ecf91f6
Show file tree
Hide file tree
Showing 29 changed files with 193 additions and 264 deletions.
4 changes: 2 additions & 2 deletions .env
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
APP_NAME=Goravel
APP_ENV=local
APP_KEY=h20Gmg7UIuUDD66gfUSUjIkPLU8KLqMK
APP_KEY=ABCDEFGHIJKLMNOPQRSTUVWXYZ123456
APP_DEBUG=true
APP_URL=http://localhost
APP_HOST=127.0.0.1
Expand All @@ -9,7 +9,7 @@ APP_PORT=3000
GRPC_HOST=127.0.0.1
GRPC_PORT=3001

JWT_SECRET=L9qknFZyWHDSVXXe1TjUsR7XQsxkbb8B
JWT_SECRET=ABCDEFGHIJKLMNOPQRSTUVWXYZ123456

LOG_CHANNEL=stack
LOG_LEVEL=debug
Expand Down
7 changes: 5 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ APP_URL=http://localhost
APP_HOST=127.0.0.1
APP_PORT=3000

GRPC_HOST=127.0.0.1
GRPC_PORT=3001
GRPC_HOST=
GRPC_PORT=

JWT_SECRET=

Expand All @@ -21,6 +21,9 @@ DB_DATABASE=goravel
DB_USERNAME=root
DB_PASSWORD=

SESSION_DRIVER=file
SESSION_LIFETIME=120

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=
REDIS_PORT=6379
Expand Down
9 changes: 0 additions & 9 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,6 @@ jobs:
go: [ "1.21", "1.22" ]
runs-on: ubuntu-latest
steps:
# - name: Set up PostgreSQL
# uses: harmon758/postgresql-action@v1
# with:
# postgresql version: '11'
# postgresql db: 'goravel'
# postgresql user: 'goravel'
# postgresql password: 'goravel'
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
Expand All @@ -33,7 +26,5 @@ jobs:
${{ runner.os }}-go-
- name: Install dependencies
run: go mod tidy
- name: Run migrate
run: go run . artisan migrate
- name: Run tests
run: go test -timeout 1h ./...
7 changes: 4 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.18.3-alpine3.16 AS builder
FROM golang:alpine AS builder

ENV GO111MODULE=on \
CGO_ENABLED=0 \
Expand All @@ -10,14 +10,15 @@ COPY . .
RUN go mod tidy
RUN go build --ldflags "-extldflags -static" -o main .

FROM alpine:3.16
FROM alpine:latest

WORKDIR /www

COPY --from=builder /build/main /www/
COPY --from=builder /build/database/ /www/database/
COPY --from=builder /build/public/ /www/public/
COPY --from=builder /build/storage/ /www/storage/
COPY --from=builder /build/resources/ /www/resources/
COPY --from=builder /build/.env /www/.env

ENTRYPOINT ["/www/main"]
ENTRYPOINT ["/www/main"]
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ Welcome to star, PR and issues!

### Integration of single page application into the framework

[routes/web.go](https://github.com/goravel/example/blob/master/routes/web.go#L41)
[routes/web.go](https://github.com/goravel/example/blob/master/routes/web.go#L44)

### View nesting

[routes/web.go](https://github.com/goravel/example/blob/master/routes/web.go#L52)
[routes/web.go](https://github.com/goravel/example/blob/master/routes/web.go#L53)

### Localization

[routes/web.go](https://github.com/goravel/example/blob/master/routes/web.go#L60)
[routes/web.go](https://github.com/goravel/example/blob/master/routes/web.go#L61)

### Session

Expand Down
6 changes: 3 additions & 3 deletions README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ Laravel!

### 单页面前端应用集成到框架

[routes/web.go](https://github.com/goravel/example/blob/master/routes/web.go#L43)
[routes/web.go](https://github.com/goravel/example/blob/master/routes/web.go#L44)

### 视图嵌套

[routes/web.go](https://github.com/goravel/example/blob/master/routes/web.go#L52)
[routes/web.go](https://github.com/goravel/example/blob/master/routes/web.go#L53)

### 本地化

[routes/web.go](https://github.com/goravel/example/blob/master/routes/web.go#L60)
[routes/web.go](https://github.com/goravel/example/blob/master/routes/web.go#L61)

### Session

Expand Down
2 changes: 2 additions & 0 deletions app/http/kernel.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package http

import (
"github.com/goravel/framework/contracts/http"
httpmiddleware "github.com/goravel/framework/http/middleware"
"github.com/goravel/framework/session/middleware"
)

Expand All @@ -12,6 +13,7 @@ type Kernel struct {
// These middleware are run during every request to your application.
func (kernel Kernel) Middleware() []http.Middleware {
return []http.Middleware{
httpmiddleware.Throttle("global"),
middleware.StartSession(),
}
}
20 changes: 18 additions & 2 deletions app/providers/route_service_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package providers

import (
"github.com/goravel/framework/contracts/foundation"
contractshttp "github.com/goravel/framework/contracts/http"
"github.com/goravel/framework/facades"
"github.com/goravel/framework/http/limit"

"goravel/app/http"
"goravel/routes"
Expand All @@ -15,9 +17,23 @@ func (receiver *RouteServiceProvider) Register(app foundation.Application) {
}

func (receiver *RouteServiceProvider) Boot(app foundation.Application) {
//Add HTTP middleware
// Add HTTP middleware
facades.Route().GlobalMiddleware(http.Kernel{}.Middleware()...)

//Add routes
receiver.configureRateLimiting()

// Add routes
routes.Web()
}

func (receiver *RouteServiceProvider) configureRateLimiting() {
facades.RateLimiter().For("global", func(ctx contractshttp.Context) contractshttp.Limit {
return limit.PerMinute(1000)
})
facades.RateLimiter().ForWithLimits("login", func(ctx contractshttp.Context) []contractshttp.Limit {
return []contractshttp.Limit{
limit.PerDay(1000),
limit.PerMinute(5).By(ctx.Request().Ip()),
}
})
}
23 changes: 15 additions & 8 deletions config/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/goravel/framework/route"
"github.com/goravel/framework/schedule"
"github.com/goravel/framework/session"
"github.com/goravel/framework/support/carbon"
"github.com/goravel/framework/testing"
"github.com/goravel/framework/translation"
"github.com/goravel/framework/validation"
Expand Down Expand Up @@ -53,25 +54,31 @@ func init() {

// Application Timezone
//
// Here you may specify the default timezone for your application, which
// will be used by the PHP date and date-time functions. We have gone
// ahead and set this to a sensible default for you out of the box.
"timezone": "UTC",
// Here you may specify the default timezone for your application.
// Example: UTC, Asia/Shanghai
// More: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
"timezone": carbon.UTC,

// Application Locale Configuration
//
// The application locale determines the default locale that will be used
// by the translation service provider.You are free to set this value
// by the translation service provider. You are free to set this value
// to any of the locales which will be supported by the application.
"locale": "en",

// Application Fallback Locale
//
// The fallback locale determines the locale to use when the current one
// is not available.You may change the value to correspond to any of
// is not available. You may change the value to correspond to any of
// the language folders that are provided through your application.
"fallback_locale": "cn",

// Application Lang Path
//
// The path to the language files for the application. You may change
// the path to a different directory if you would like to customize it.
"lang_path": "lang",

// Encryption Key
//
// 32 character string, otherwise these encrypted strings
Expand All @@ -96,10 +103,10 @@ func init() {
&grpc.ServiceProvider{},
&mail.ServiceProvider{},
&auth.ServiceProvider{},
&hash.ServiceProvider{},
&crypt.ServiceProvider{},
&filesystem.ServiceProvider{},
&validation.ServiceProvider{},
&crypt.ServiceProvider{},
&hash.ServiceProvider{},
&session.ServiceProvider{},
&translation.ServiceProvider{},
&testing.ServiceProvider{},
Expand Down
2 changes: 1 addition & 1 deletion config/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func init() {
// Here you may define all the cache "stores" for your application as
// well as their drivers. You may even define multiple stores for the
// same cache driver to group types of items stored in your caches.
// Available Drivers: "memory", "redis", "custom"
// Available Drivers: "memory", "custom"
"stores": map[string]any{
"memory": map[string]any{
"driver": "memory",
Expand Down
2 changes: 1 addition & 1 deletion config/cors.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func init() {
"allowed_methods": []string{"*"},
"allowed_origins": []string{"*"},
"allowed_headers": []string{"*"},
"exposed_headers": []string{"*"},
"exposed_headers": []string{""},
"max_age": 0,
"supports_credentials": false,
})
Expand Down
2 changes: 1 addition & 1 deletion config/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
func init() {
config := facades.Config()
config.Add("database", map[string]any{
// Default database connection name, only support Mysql now.
// Default database connection name
"default": config.Env("DB_CONNECTION", "mysql"),

// Database connections
Expand Down
11 changes: 8 additions & 3 deletions config/filesystems.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package config

import (
"github.com/goravel/framework/facades"
"github.com/goravel/framework/support/path"
)

func init() {
Expand All @@ -20,12 +21,16 @@ func init() {
// may even configure multiple disks of the same driver. Defaults have
// been set up for each driver as an example of the required values.
//
// Supported Drivers: "local", "s3", "oss", "cos", "custom"
// Supported Drivers: "local", "custom"
"disks": map[string]any{
"local": map[string]any{
"driver": "local",
"root": "storage/app",
"url": config.Env("APP_URL").(string) + "/storage",
"root": path.Storage("app"),
},
"public": map[string]any{
"driver": "local",
"root": path.Storage("app/public"),
"url": config.Env("APP_URL", "").(string) + "/storage",
},
},
})
Expand Down
4 changes: 2 additions & 2 deletions config/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import (
func init() {
config := facades.Config()
config.Add("grpc", map[string]any{
// Grpc Configuration
//
// Configure your server host
"host": config.Env("GRPC_HOST", ""),

// Configure your server port
"port": config.Env("GRPC_PORT", ""),

// Configure your client host and interceptors.
Expand Down
26 changes: 13 additions & 13 deletions config/hashing.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,20 @@ func init() {
//
// This option controls the default diver that gets used
// by the framework hash facade.
// Default driver is "argon2id", because it is the most secure.
// Default driver is "bcrypt".
//
// Supported Drivers: "argon2id", "bcrypt"
"driver": "argon2id",
// Supported Drivers: "bcrypt", "argon2id"
"driver": "bcrypt",

// Bcrypt Hashing Options
// rounds: The cost factor that should be used to compute the bcrypt hash.
// The cost factor controls how much time is needed to compute a single bcrypt hash.
// The higher the cost factor, the more hashing rounds are done. Increasing the cost
// factor by 1 doubles the necessary time. After a certain point, the returns on
// hashing time versus attacker time are diminishing, so choose your cost factor wisely.
"bcrypt": map[string]any{
"rounds": 12,
},

// Argon2id Hashing Options
// memory: A memory cost, which defines the memory usage, given in kibibytes.
Expand All @@ -26,15 +36,5 @@ func init() {
"time": 4,
"threads": 1,
},

// Bcrypt Hashing Options
// rounds: The cost factor that should be used to compute the bcrypt hash.
// The cost factor controls how much time is needed to compute a single bcrypt hash.
// The higher the cost factor, the more hashing rounds are done. Increasing the cost
// factor by 1 doubles the necessary time. After a certain point, the returns on
// hashing time versus attacker time are diminishing, so choose your cost factor wisely.
"bcrypt": map[string]any{
"rounds": 10,
},
})
}
3 changes: 3 additions & 0 deletions config/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ func init() {
// HTTP Drivers
"drivers": map[string]any{
"gin": map[string]any{
// Optional, default is 4096 KB
"body_limit": 4096,
"header_limit": 4096,
"route": func() (route.Route, error) {
return ginfacades.Route("gin"), nil
},
Expand Down
2 changes: 1 addition & 1 deletion config/jwt.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func init() {
// the original token being created until they must re-authenticate.
// Defaults to 2 weeks.
//
// You can also set this to null, to yield an infinite refresh time.
// You can also set this to 0, to yield an infinite refresh time.
// Some may want this instead of never expiring tokens for e.g. a mobile app.
// This is not particularly recommended, so make sure you have appropriate
// systems in place to revoke the token if necessary.
Expand Down
2 changes: 1 addition & 1 deletion config/mail.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import "github.com/goravel/framework/facades"

func init() {
config := facades.Config()
facades.Config().Add("mail", map[string]any{
config.Add("mail", map[string]any{
// SMTP Host Address
//
// Here you may provide the host address of the SMTP server used by your
Expand Down
25 changes: 0 additions & 25 deletions config/route.go

This file was deleted.

Loading

0 comments on commit ecf91f6

Please sign in to comment.