Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
7294f90
chore: quick update fix/router at 2026-01-11 14:49:51
kooksee Jan 11, 2026
59c44d0
chore: quick update fix/router at 2026-01-11 20:17:43
kooksee Jan 11, 2026
56c7df2
chore: quick update fix/router at 2026-01-12 21:49:58
kooksee Jan 12, 2026
fabd282
chore: quick update fix/router at 2026-01-19 13:31:33
kooksee Jan 19, 2026
7e4306a
chore: quick update fix/router at 2026-01-19 16:05:06
kooksee Jan 19, 2026
d2e3fa0
chore: quick update fix/router at 2026-01-19 16:23:57
kooksee Jan 19, 2026
59ee1ee
chore: quick update fix/router at 2026-01-19 16:30:16
kooksee Jan 19, 2026
7dcde43
chore: quick update fix/router at 2026-01-19 18:17:00
kooksee Jan 19, 2026
e9d1a5e
chore: quick update fix/router at 2026-01-20 00:31:56
kooksee Jan 19, 2026
e160430
chore: quick update fix/router at 2026-01-20 17:03:09
kooksee Jan 20, 2026
5b0148e
chore: quick update fix/router at 2026-01-20 18:56:48
kooksee Jan 20, 2026
a0a8edf
chore: quick update fix/router at 2026-01-20 19:15:42
kooksee Jan 20, 2026
8db3040
chore: quick update fix/router at 2026-01-20 23:32:26
kooksee Jan 20, 2026
35667f2
chore: quick update fix/router at 2026-01-20 23:49:57
kooksee Jan 20, 2026
c2acf71
chore: quick update fix/router at 2026-01-22 10:00:16
kooksee Jan 22, 2026
b9faf26
chore: quick update fix/router at 2026-01-22 10:00:55
kooksee Jan 22, 2026
a920adc
chore: quick update fix/router at 2026-01-24 01:26:59
kooksee Jan 23, 2026
93e8577
chore: quick update fix/router at 2026-01-24 12:24:39
kooksee Jan 24, 2026
fb88d13
chore: quick update fix/router at 2026-01-26 18:45:52
kooksee Jan 26, 2026
8e11b15
chore: quick update fix/router at 2026-01-27 09:51:08
kooksee Jan 27, 2026
4bd9213
chore: quick update fix/router at 2026-01-27 10:17:15
kooksee Jan 27, 2026
362a661
chore: quick update fix/router at 2026-01-27 10:23:20
kooksee Jan 27, 2026
6c22433
chore: quick update fix/router at 2026-01-27 10:23:57
kooksee Jan 27, 2026
75e3935
chore: quick update fix/router at 2026-01-27 11:47:13
kooksee Jan 27, 2026
aa6fc06
chore: quick update fix/router at 2026-01-27 15:53:56
kooksee Jan 27, 2026
6791e7c
refactor(clients/resty): extract common utilities and improve code or…
kooksee Jan 28, 2026
568919a
test(resty): add unit tests for request creation and building
kooksee Jan 28, 2026
b40a43a
chore: quick update fix/router at 2026-01-31 16:30:16
kooksee Jan 31, 2026
16011e8
chore: quick update fix/router at 2026-01-31 17:06:41
kooksee Jan 31, 2026
8aa101a
chore: quick update fix/router at 2026-01-31 17:14:42
kooksee Jan 31, 2026
2e22952
chore: quick update fix/router at 2026-01-31 17:16:52
kooksee Jan 31, 2026
0c2636c
chore: quick update fix/router at 2026-01-31 18:31:08
kooksee Jan 31, 2026
546a827
chore: quick update fix/router at 2026-02-01 10:54:00
kooksee Feb 1, 2026
726c409
chore: quick update fix/router at 2026-02-04 20:39:34
kooksee Feb 4, 2026
93c1a15
chore: quick update fix/router at 2026-02-04 21:52:50
kooksee Feb 4, 2026
b150a92
chore: quick update fix/router at 2026-02-04 21:56:18
kooksee Feb 4, 2026
08292c1
chore: quick update fix/router at 2026-02-10 14:42:36
kooksee Feb 10, 2026
e0c22ae
chore: quick update fix/router at 2026-02-10 15:07:00
kooksee Feb 10, 2026
50cc1d3
chore: quick update fix/router at 2026-02-10 16:49:44
kooksee Feb 10, 2026
314f33a
chore: quick update fix/router at 2026-02-10 18:05:32
kooksee Feb 10, 2026
e2f68a0
chore: quick update fix/router at 2026-02-10 18:17:20
kooksee Feb 10, 2026
bf6a04c
chore: quick update fix/router at 2026-02-10 18:22:05
kooksee Feb 10, 2026
230ccdd
chore: quick update fix/router at 2026-02-10 18:45:14
kooksee Feb 10, 2026
d509739
chore: quick update fix/router at 2026-02-10 19:05:16
kooksee Feb 10, 2026
e5623c2
chore: quick update fix/router at 2026-02-10 20:26:54
kooksee Feb 10, 2026
c84994b
chore: quick update fix/router at 2026-02-10 20:46:41
kooksee Feb 10, 2026
5e1ed1c
chore: quick update fix/router at 2026-02-13 00:35:30
kooksee Feb 12, 2026
4d04067
chore: quick update fix/router at 2026-02-13 00:49:24
kooksee Feb 12, 2026
430c467
chore: quick update fix/router at 2026-02-13 21:41:59
kooksee Feb 13, 2026
336e302
chore: quick update fix/router at 2026-02-13 21:50:55
kooksee Feb 13, 2026
78f83cb
chore: quick update fix/router at 2026-02-13 22:09:20
kooksee Feb 13, 2026
5b10ad7
chore: quick update fix/router at 2026-02-14 12:17:43
kooksee Feb 14, 2026
ac58db5
chore: quick update fix/router at 2026-02-14 20:41:59
kooksee Feb 14, 2026
ea4956e
chore: quick update fix/router at 2026-02-14 20:44:58
kooksee Feb 14, 2026
e6c30a0
chore: quick update fix/router at 2026-02-14 21:29:13
kooksee Feb 14, 2026
72d34a2
chore: quick update fix/router at 2026-02-14 21:39:02
kooksee Feb 14, 2026
ac31f1a
chore: quick update fix/router at 2026-02-14 21:41:37
kooksee Feb 14, 2026
79ddbcb
chore: quick update fix/router at 2026-02-14 21:43:56
kooksee Feb 14, 2026
02e0a82
chore: quick update fix/router at 2026-02-14 21:44:39
kooksee Feb 14, 2026
a8deef2
chore: quick update fix/router at 2026-02-23 17:32:47
kooksee Feb 23, 2026
7460203
chore: quick update fix/router at 2026-02-24 13:49:04
kooksee Feb 24, 2026
15d8905
refactor: update debug routes and dependencies
kooksee Feb 25, 2026
46a5543
feat: add fileserver command and remove standalone tool
kooksee Feb 25, 2026
105cc91
feat: update dix debug endpoints and dependencies
kooksee Feb 26, 2026
ebc3993
feat: add devproxy tool and resty client docs
kooksee Feb 27, 2026
89a13b0
chore: quick update fix/router at 2026-02-27 18:44:16
kooksee Feb 27, 2026
ecca222
Merge branch 'fix/router' of github.com:pubgo/lava into fix/router
kooksee Mar 18, 2026
d7be303
chore: update protoc version to v6.33.4 and adjust go_package paths i…
kooksee Mar 18, 2026
ac7e65f
chore: quick update fix/router at 2026-03-18 23:03:31
kooksee Mar 18, 2026
693a0a4
feat: 增强 gRPC Web 支持,添加服务端响应流功能并更新文档
kooksee Mar 23, 2026
310e0da
Merge branch 'fix/router' of github.com:pubgo/lava into fix/router
kooksee Mar 23, 2026
1111839
chore: 格式化 gRPC Web 文档中的表格并调整代码注释对齐
kooksee Mar 23, 2026
47e453a
feat: 添加 streamHTTP 的单元测试,验证 SendHeader 和 SetHeader 的行为
kooksee Mar 23, 2026
624b8ab
fix: 修复响应流中头部预取逻辑,确保在第一帧之前不获取头部
kooksee Mar 23, 2026
67a3580
fix: 处理重复响应流头部发送错误,增强错误日志记录
kooksee Mar 24, 2026
c292e59
fix: 更新文档格式,增强 gRPC 内容类型处理逻辑的测试覆盖
kooksee Mar 24, 2026
630e9a4
fix: 更新架构文档,增强核心组件描述和流程图可读性
kooksee Mar 24, 2026
ac8feb5
fix: 移除冗余的 gRPC Web 处理逻辑,简化 ServeHTTP 方法
kooksee Mar 24, 2026
1486d51
fix: 重命名 invokeResponseStream 方法参数,增强代码可读性
kooksee Mar 24, 2026
2a68a52
fix: 重构路由处理逻辑,简化路由函数参数类型
kooksee Mar 25, 2026
cbf700a
fix: 移除冗余的生命周期依赖,简化服务管理逻辑
kooksee Apr 1, 2026
00f3a46
chore: quick update fix/router at 2026-04-01 20:46:42
kooksee Apr 1, 2026
f1f4d11
chore: quick update fix/router at 2026-04-01 21:55:54
kooksee Apr 1, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .devproxy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
dns:
port: 1053
http:
port: 80

routes:
- pattern: "debug"
target: "localhost:8082"
path: "/debug"
358 changes: 358 additions & 0 deletions .github/copilot-instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,358 @@
# Lava Project Copilot Instructions

## Project Overview

Lava is a microservice middleware integration framework abstracted from enterprise practice. It provides a comprehensive set of tools and utilities for building microservices, including service management, tunnel system, scheduler, HTTP/gRPC servers, and various middleware components.

## Project Structure

```
├── clients/ # Client libraries (gRPC and HTTP clients)
├── cmds/ # Command-line tools
├── core/ # Core modules (supervisor, tunnel, scheduler, etc.)
├── docs/ # Documentation files
├── internal/ # Internal implementation
├── lava/ # Public interfaces
├── pkg/ # Public packages (gateway, cliutil, etc.)
├── proto/ # Protobuf definitions
├── servers/ # Server implementations (HTTP and gRPC)
├── tools/ # Development tools
├── go.mod # Go module file
├── go.sum # Go module checksum file
├── taskfile.yml # Task configuration
└── README.md # Project README
```

## Core Modules

### clients/
- **grpcc/**: gRPC client implementation with load balancing and middleware support
- **resty/**: HTTP client implementation with middleware support

### cmds/
- Various command-line tools like `lavacurl`, `configcmd`, `healthcmd`, etc.

### core/
- **supervisor/**: Service lifecycle management
- **tunnel/**: Service proxy and intranet penetration
- **scheduler/**: Task scheduling system
- **logging/**: Unified logging system
- **metrics/**: Unified metrics system
- **tracing/**: Distributed tracing system
- **encoding/**: Unified encoding system
- **discovery/**: Service discovery system
- **debug/**: Debugging utilities
- **lavabuilder/**: Dependency injection setup

### internal/
- **configs/**: Configuration files
- **examples/**: Example applications
- **middlewares/**: Internal middleware implementations

### lava/
- Public interfaces and core types

### pkg/
- **gateway/**: gRPC Gateway implementation
- **cliutil/**: Command-line utility functions
- **httputil/**: HTTP utility functions
- **grpcutil/**: gRPC utility functions
- **netutil/**: Network utility functions

### servers/
- **https/**: HTTP server implementation based on Fiber
- **grpcs/**: gRPC server implementation with gateway support

## Coding Style

### Go Code Style
- Follow the standard Go code style (use `go fmt`)
- Use 4 spaces for indentation
- Keep lines under 100 characters
- Use clear, descriptive variable and function names
- Use camelCase for variables and functions
- Use PascalCase for types and interfaces
- Use ALL_CAPS for constants

### Naming Conventions
- **Packages**: Lowercase, single-word names
- **Functions**: CamelCase, descriptive names
- **Variables**: CamelCase, short but descriptive
- **Types**: PascalCase, descriptive names
- **Constants**: ALL_CAPS, with underscores

### Error Handling
- Use `github.com/pkg/errors` for error wrapping
- Return errors as the last return value
- Check and handle all errors
- Provide clear, descriptive error messages

### Documentation
- Use GoDoc format for documentation
- Document all public functions, types, and packages
- Use clear, concise language
- Include examples where appropriate

## Architecture Principles

### Dependency Injection
- Use the `dix` framework for dependency injection
- Register dependencies in the `lavabuilder`
- Use constructor functions for creating services

### Middleware Pattern
- Use middleware for cross-cutting concerns
- Implement the `lava.Middleware` interface
- Chain middleware for HTTP and gRPC requests

### Configuration Management
- Use hierarchical YAML configuration
- Support environment variable overrides
- Use structured configuration types

### Service Lifecycle
- Register services with the `supervisor`
- Implement the `lava.Service` interface
- Handle graceful shutdown

## Common Patterns

### Creating a Service
```go
func New() lava.Service {
return &MyService{}
}

type MyService struct{}

func (s *MyService) String() string {
return "my-service"
}

func (s *MyService) Serve(ctx context.Context) error {
// Service implementation
<-ctx.Done()
return nil
}
```

### Creating Middleware
```go
func New() lava.Middleware {
return &MyMiddleware{}
}

type MyMiddleware struct{}

func (m *MyMiddleware) Handle(ctx context.Context, req interface{}) (interface{}, error) {
// Middleware implementation
return req, nil
}
```

### Registering Services
```go
func main() {
di := lavabuilder.New()
di.Provide(func() lava.Service {
return MyService.New()
})
lavabuilder.Run(di)
}
```

### HTTP Server Setup
```go
https.New(https.Params{
Handlers: []lava.HttpRouter{
&UserRouter{},
},
Middlewares: []lava.Middleware{
middleware.New(),
},
})
```

### gRPC Server Setup
```go
grpcs.New(grpcs.Params{
GrpcRouters: []lava.GrpcRouter{
&UserService{},
},
Middlewares: []lava.Middleware{
middleware.New(),
},
})
```

## Project-Specific Tools

### Task Commands
- `task test`: Run all tests
- `task lint`: Run linting
- `task build`: Build the project
- `task clean`: Clean build artifacts
- `task proto:gen`: Generate Protobuf code

### Command-Line Tools
- `lavacurl`: HTTP/gRPC client for testing APIs
- `lava config`: Manage configuration
- `lava health`: Check service health
- `lava scheduler`: Manage scheduled tasks
- `lava tunnel`: Manage tunnel connections

## Common Dependencies

### Core Dependencies
- `github.com/gofiber/fiber/v3`: HTTP server framework
- `google.golang.org/grpc`: gRPC framework
- `github.com/pubgo/dix`: Dependency injection framework
- `github.com/pubgo/redant`: Command-line framework
- `github.com/prometheus/client_golang`: Metrics collection
- `github.com/opentracing/opentracing-go`: Distributed tracing
- `github.com/pkg/errors`: Error handling
- `github.com/spf13/viper`: Configuration management

### Testing Dependencies
- `github.com/stretchr/testify`: Testing assertions
- `github.com/golang/mock`: Mock generation

## Development Workflow

1. **Branch Management**: Use `main` for stable releases, `develop` for features, and feature branches for new work
2. **Commit Messages**: Use conventional commit messages (`feat:`, `fix:`, `docs:`, etc.)
3. **Testing**: Write comprehensive tests with at least 80% coverage
4. **Linting**: Run `golangci-lint` before committing
5. **Documentation**: Update documentation for new features and changes

## Best Practices

### Performance
- Use connection pooling for HTTP/gRPC clients
- Avoid unnecessary allocations
- Use appropriate data structures
- Implement caching where appropriate

### Security
- Use HTTPS for all communications
- Implement proper authentication and authorization
- Validate all user input
- Use secure coding practices

### Reliability
- Implement graceful shutdown
- Use timeouts for all network operations
- Handle errors properly
- Implement circuit breakers for external dependencies

### Maintainability
- Write clean, readable code
- Follow Go idioms and conventions
- Document all public APIs
- Use consistent naming and formatting

## Examples

### Simple HTTP Service
```go
package main

import (
"github.com/pubgo/lava/v2/core/lavabuilder"
"github.com/pubgo/lava/v2/servers/https"
"github.com/pubgo/lava/v2/lava"
"github.com/gofiber/fiber/v3"
)

// UserRouter handles user-related routes
type UserRouter struct{}

func (r *UserRouter) Prefix() string {
return "/users"
}

func (r *UserRouter) Middlewares() []lava.Middleware {
return nil
}

func (r *UserRouter) Router(router fiber.Router) {
router.Get("/", r.GetUsers)
router.Get("/:id", r.GetUser)
}

func (r *UserRouter) GetUsers(c *fiber.Ctx) error {
return c.JSON([]map[string]interface{}{
{"id": "1", "name": "John"},
{"id": "2", "name": "Jane"},
})
}

func (r *UserRouter) GetUser(c *fiber.Ctx) error {
id := c.Params("id")
return c.JSON(map[string]interface{}{
"id": id,
"name": "John",
})
}

func main() {
di := lavabuilder.New()
di.Provide(func() lava.Service {
return https.New(https.Params{
Handlers: []lava.HttpRouter{
&UserRouter{},
},
})
})
lavabuilder.Run(di)
}
```

### gRPC Service with Gateway
```go
package main

import (
"github.com/pubgo/lava/v2/core/lavabuilder"
"github.com/pubgo/lava/v2/servers/grpcs"
"github.com/pubgo/lava/v2/lava"
)

// UserService handles user-related gRPC requests
type UserService struct{}

func (s *UserService) ServiceDesc() *grpc.ServiceDesc {
return &pb.UserService_ServiceDesc
}

func (s *UserService) Register(server grpc.ServiceRegistrar) {
pb.RegisterUserServiceServer(server, s)
}

func (s *UserService) GetUser(ctx context.Context, req *pb.GetUserRequest) (*pb.GetUserResponse, error) {
return &pb.GetUserResponse{
User: &pb.User{
Id: req.GetUserId(),
Name: "John",
},
}, nil
}

func main() {
di := lavabuilder.New()
di.Provide(func() lava.Service {
return grpcs.New(grpcs.Params{
GrpcRouters: []lava.GrpcRouter{
&UserService{},
},
})
})
lavabuilder.Run(di)
}
```

## Conclusion

Lava is a comprehensive framework for building microservices, providing a wide range of tools and utilities to simplify development. By following the guidelines and best practices outlined in this document, you can build robust, scalable, and maintainable microservices using the Lava framework.

For more detailed information, refer to the project documentation in the `docs/` directory.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,5 @@ bin
/example/bin
.proto
proto-vendor
.local
/internal/examples/grpcweb/frontend/node_modules
Loading