Golang? ? ?????? ???? ?? ??? ?? Buffalo ?????
Jun 24, 2023 am 08:37 AM?? ???? ???? ??? ???? ?? ?? ???? ???? ??? ??????. ?? ???? ????? ?? ?? ???? ?? ??? ?????. ? ????? ? ???? ????? ?? ?? ?? ??? ????? ??? ??? ? ????. ??? ???? ?? ????? ??? ??? ? ?? ?????? ?????. ? ???? Golang? Buffalo ?????? ???? ?? ???? ???? ??? ?????.
Golang? ???? ????? ???? ?? ????? Golang? ???? ?? ?? ???? ????. ??? ??? ?? ??? Golang? ??????. Buffalo ?????? ??? ??? ?? ??? ????? ???? ?? ?? Golang ? ????????. ? ???????? ??? ???? ???? ??????? ???? ??? ? ????.
?? ???? ?? ? ?? ??? ???? ???.
- ?? ??: ?? ???? ???? ?? ????? ?? ???? ???. ?? ???? ?? RESTful API ?? gRPC ????? ??? ? ????.
- ??? ???: ?? ???? ???? ?????? ?? ?? ???? ?? ? ????. ??? ??? ? ???? ????? ??? ???? ???.
- ?? ???: ?? ???? ?? ????? ??? ???? ??? ??? ???? ???? ???? ??? ???? ???.
?? Buffalo ?????? ???? ??? ??? ???? ??? ???????.
Buffalo ?????? ???
?? ??? Buffalo ??????? ???? ???. Buffalo CLI? ???? ? ??? ??? ? ????. Buffalo CLI? ???? ?? ???? ?? ? Buffalo ??????? ?????.
$ go get -u -v github.com/gobuffalo/buffalo/cli/v2 $ buffalo new appname
Buffalo? ?? ?????? ??? ?????. ?? ??? ???? ??? ??? ? ????.
$ buffalo dev
? ??? ? ??? ??? ?? ?????? http://127.0.0.1:3000? ???? ??????? ? ? ????.
RESTful API ???
???? ?? ???? ????? ?? ??? ? ?? RESTful API? ???? ???. Buffalo ?????? ??? ???? ???? ? ??? ??? ? ????.
?? API ??? ???? ????? ???? ???. ?? ??? ???? ????? ?? ? ????.
$ buffalo generate resource user name email
? ??? "user"?? ????? ???? ?????? "name"? "email"??? ? ?? ?? ??? ???? ????. ??? ??? ??? ??? ? ??? ????? ??? ??? ? ????.
?? ???? ???? ?? ????? POST ? GET ??? ???? ???. ??? ??? ???? ?? ????? ?? ??? ??? ? ????.
func (v *UsersResource) Create(c buffalo.Context) error { user := &models.User{} if err := c.Bind(user); err != nil { return err } // Add validation logic here! tx := c.Value("tx").(*pop.Connection) if err := tx.Create(user); err != nil { return err } return c.Render(201, r.JSON(user)) } func (v *UsersResource) List(c buffalo.Context) error { users := &models.Users{} tx := c.Value("tx").(*pop.Connection) if err := tx.All(users); err != nil { return err } return c.Render(200, r.JSON(users)) }
? ??? POST ? GET ??? ???? JSON ??? ?? ???? ?????? ?????.
gRPC ???? ??
RESTful API ??? gRPC ????? ???? ??? ? ??? ??? ?? ????. Buffalo ?????? gRPC ????? ???? ?? ??? ???? Buffalo-gRPC ????? ??? ? ????.
$ buffalo plugins install buffalo-grpc
???? ??????? ?? gRPC ??? ??? ???? ???. ?? ??? ???? ??? ??? ? ????.
$ buffalo generate grpc user
? ??? "user"?? gRPC ???? ?????.
??? ????? gRPC ???? ??? ???? ???? ???. ?? ???? ??? ???? ??? ? ????.
type UserServer struct{} func (s *UserServer) GetUser(ctx context.Context, req *user.GetUserRequest) (*user.GetUserResponse, error) { // Insert user retrieval logic here } func (s *UserServer) CreateUser(ctx context.Context, req *user.CreateUserRequest) (*user.User, error) { // Insert user creation logic here }
????? ???? ?? ??? ???? gRPC ???? ??? ? ????.
conn, err := grpc.Dial("localhost:50051", grpc.WithInsecure()) if err != nil { log.Fatalf("failed to connect: %s", err) } defer conn.Close() client := user.NewUserClient(conn) res, err := client.GetUser(context.Background(), &user.GetUserRequest{Id: "123"}) if err != nil { log.Fatalf("failed to get user: %s", err) } log.Printf("user: %v", res)
?? ????? Redis? ??? ??
?? ????? ??? ??? ??? ??? ?? ????? ??? ?????. Redis? ?? ???? ???? ???? ??? ???? ??? ? ?? ??? ?? ?? ?? ?????. ?? ??? ???? Redis? ??? ? ????.
$ brew install redis
???? ???????? Redis? ??? ??? ? ????. ?? ??? ???? Redis ????? ??? ? ????.
$ buffalo plugins install buffalo-redis
???? ???????? ?? ??? ???? Redis? ??? ? ????.
var ( RedisClient *redis.Client ) func init() { RedisClient = redis.NewClient(&redis.Options{ Addr: "localhost:6379", }) } func main() { app := buffalo.New(buffalo.Options{}) app.Use(midware.Redis(RedisClient)) // ... }
???? ?????? ?? ??? ???? Redis ??? ???? ??? ? ????. :
func (v *UsersResource) Create(c buffalo.Context) error { user := &models.User{} if err := c.Bind(user); err != nil { return err } // Add validation logic here! if err := RedisClient.Set("user_"+user.ID.String(), user, 0).Err(); err != nil { return err } // Add logic to store user in database return c.Render(201, r.JSON(user)) }
? ???? ??? ID? ?? ???? ???? Redis ??? ?????. ?? ?? ??? ??? ???? ???? ??? ? ????.
?? ??? ??
????? ?? ??? ??? ???? ???. ?? ????? ??? ??? ??? ?? ??? ???? ?? ???? ??? ? ??? ????. ? ??? ???? ?? ??? ??? ??? ??? ? ????.
Nginx? ?? ??? ? HTTPS ???? ???? ?? ?? ??? ??? ?????. ??? Nginx? ???? ?? ?? ??? ???? ?? ???? ??? ? ????.
http { upstream app_servers { server 127.0.0.1:3001; server 127.0.0.1:3002; server 127.0.0.1:3003; } server { listen 80; server_name example.com; location / { proxy_pass http://app_servers; } } }
? ?? ??? ??? ? ?? ?? ??? ???? ??? ?? ????? ???? ??? ??? ??? ?????.
??
Buffalo ?????? ???? ?? ???? ???? ???? RESTful API ? gRPC? ??? ?? ?? ????? ??? ? ????. ?? Redis? ???? ??? ??? ??? ???? ??? ??? ??? ??? ?? ???? ??? ? ????. ??? ??? ?? ??? ?? ???? ?? ????? ??? ? ?? ??? ??? ??? ? ????.
? ??? Golang? ? ?????? ???? ?? ??? ?? Buffalo ?????? ?? ?????. ??? ??? PHP ??? ????? ?? ?? ??? ?????!

? AI ??

Undress AI Tool
??? ???? ??

Undresser.AI Undress
???? ?? ??? ??? ?? AI ?? ?

AI Clothes Remover
???? ?? ???? ??? AI ?????.

Clothoff.io
AI ? ???

Video Face Swap
??? ??? AI ?? ?? ??? ???? ?? ???? ??? ?? ????!

?? ??

??? ??

???++7.3.1
???? ?? ?? ?? ???

SublimeText3 ??? ??
??? ??, ???? ?? ????.

???? 13.0.1 ???
??? PHP ?? ?? ??

???? CS6
??? ? ?? ??

SublimeText3 Mac ??
? ??? ?? ?? ?????(SublimeText3)

??? ??











Go??? ???? ??? ?? ?? ?? ?????. ??? ??? ????. ?? ?? ?? ??? ???? ?? ?? ?? ?? ??? ?? ???? ?? ?? ?? ?? ??? ??? ??? ??? ??????? ???? ?????.

Golang? ?? ?? ? ?? ????? ???? C? ??? ?? ? ??? ??? ??? ????? ?????. 1) Golang? ??? ?? ? ??? ????? ?? ??? ?????, ??? ? ??? ??? ?????. 2) C? ?? ??? ?? ? ???? ???? ?? ??? ? ??? ???? ???? ??? ??? ?????.

Golang? ????? C?? ?? C? ?? ???? Golang?? ????. 1) Golang? Goroutine ? Channel? ?? ???? ???? ????, ?? ?? ?? ??? ???? ? ?????. 2) C ???? ??? ? ?? ?????? ?? ????? ??? ???? ???? ??? ???? ??? ??????? ?????.

??? ?? ?? : ??? ???? ??? ????? ??? ???? ?????? ?? ??? ??? ?? ???? ???? ??? ????? ?? Nodejs? ??? ??? ????.

GO? ?? ?????? ????? ? ??? ?? ?? ?????? ?? ????? GO? ????? ? ? ???? ?? ? ?? ???? ??? ????.

Golang? ??? ?? ? ???? Python?? ????. 1) Golang? ??? ?? ??? ???? ??? ??? ?? ??? ?????? ? ?????. 2) ?? ? ???? ???? ??? ????? Cython? ?? ??? ?? ??? ??? ? ? ????.

Go Language? ????? ?? ??? ???? ???? ? ? ?????. ??? ??? ????. 1. ??? : ?? ??? ???, ?? ??? ??; 2. ?? ????? : ?? ?? ? ??? ?? ?? ??? ???; 3. ??? : ??? ??, ?? ? ?? ?? ?? ??; 4. ??? ??? : ??? ??? ???, ?? ??? ?????.

Golang? Python? ?? ?? ? ??? ????. Golang? ??? ? ?? ?????? ????? Python? ??? ?? ? ? ??? ?????. Golang? ??? ??? ???? ???? ???? Python? ??? ?? ? ??? ????? ???? ?????.
