TungNT (Blue)

tungnt.blue@gmail.com

User Tools

Site Tools


development:goravel

Install

https://www.goravel.dev/getting-started/installation.html

git clone https://github.com/goravel/goravel.git && rm -rf goravel/.git*
 
mv goravel goravel.example.com
 
cp .env.example .env
 
# Tải tất cả các dependencies được khai báo trong go.mod.
# Xóa các dependencies không cần thiết.
# Cập nhật file go.sum.
go mod tidy
 
go run . artisan key:generate
 
# You need to generate JWT Token if you use Authentication.
go run . artisan jwt:secret

$GOPATH, mặc định là ~/go/bin

export GOROOT=/usr/local/go
export GOPATH=$HOME/go
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin

Thêm Module

File go.mod:

module your_project_name
 
go 1.21
 
require (
    github.com/goravel/framework v1.0.0
)

Ví dụ: nếu github.com/goravel/framework chưa được khai báo, thêm nó vào require hoặc sử dụng lệnh sau để thêm module:

go get github.com/goravel/framework

Xóa và tải lại module

Xóa cache của Go:

go clean -modcache

Tải lại tất cả dependencies:

go mod tidy

Tải Air qua Go

go install github.com/cosmtrek/air@latest

Start HTTP Service

go run .
go run main.go

air

https://github.com/air-verse/air

go run .

~/go/bin/air -c .air.toml

Build web server

supervisor

[program:goravel]
process_name=%(program_name)s_%(process_num)02d
;command=/usr/local/go/bin/go run /private/var/www/examples/goravel.example.com/main.go
command=/Users/tungnt/go/bin/air -c /private/var/www/examples/goravel.example.com/.air.toml
directory=/private/var/www/examples/goravel.example.com
autostart=true
autorestart=true
user=tungnt
redirect_stderr=true
stdout_logfile=/private/var/www/examples/goravel.example.com/storage/logs/horizon.log
stopwaitsecs=3600

nginx config

server {
    listen 80;
    server_name goravel.example.com;

    location / {
        proxy_pass http://localhost:3000;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
    }
}

server {
        listen       443 ssl;

        server_name goravel.example.com;

        ssl_certificate     /opt/homebrew/etc/nginx/ssl/goravel.example.com.pem;
        ssl_certificate_key /opt/homebrew/etc/nginx/ssl/goravel.example.com-key.pem;

        ssl_session_timeout 5m;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers  HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers on;

    location / {
        proxy_pass http://localhost:3000;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
    }

}

The Basic

Controllers

go run . artisan make:controller test/ExampleController

go run . artisan make:controller --resource PhotoController

Middleware

go run . artisan make:middleware ApiAuth
app/http/kernel.go
package http
 
import (
	"github.com/goravel/framework/contracts/http"
 
	"goravel/app/http/middleware"
)
 
type Kernel struct {
}
 
// The application's global HTTP middleware stack.
// These middleware are run during every request to your application.
func (kernel Kernel) Middleware() []http.Middleware {
	return []http.Middleware{
		middleware.ApiAuth(),
	}
}
routes/api.go
import "github.com/goravel/framework/http/middleware"
 
facades.Route().Middleware(middleware.Auth()).Get("users", userController.Show)

Request

go run . artisan make:request test/ExamplePostRequest

Rule

go run . artisan make:rule Uppercase
development/goravel.txt · Last modified: 2024/11/28 05:04 by tungnt

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki