项目文件夹

文件
Asim Aslam c7657f73f4
goreleaser / goreleaser (push) Has been cancelled
Refactor agent plan storage, update docs, and release v6 (#2977)
* test(harness): read agent plan from the scoped store

The store-scoping change moved an agent's plan from the default table
key agent/{name}/plan to its own table (database "agent", table {name},
key "plan"). The plan-delegate harness tests still read the old key and
failed with 'not found'; read through store.Scope(mem, "agent", name)
like the agent does.

* docs: orient agents-first across README, landing, and docs overview

Lead with agents (then services and flows), surface MCP + A2A as the
interop story, and frame agents as services. Landing hero and feature
grid reordered agents-first with an A2A gateway card.

* v6: module path go-micro.dev/v6, TLS secure by default, NewService

Cut v6. Three breaking changes, bundled so the major bump is paid once:

- Module path go-micro.dev/v5 -> go-micro.dev/v6 across all imports + go.mod.
- TLS verification on by default (was off). MICRO_TLS_SECURE removed;
  MICRO_TLS_INSECURE=true opts out for self-signed/dev.
- micro.NewService(name, opts...) is the canonical service constructor,
  symmetric with NewAgent/NewFlow; micro.New kept as a deprecated alias;
  the old name-less NewService(opts...) removed. Generators emit NewService.

Also ports the JWT auth token provider in-module (go-micro.dev/v6/auth/jwt/token
on golang-jwt/jwt/v5), dropping the v5-pinned github.com/micro/plugins/v5/auth/jwt
and the deprecated dgrijalva/jwt-go.

Docs/README/landing updated to v6 and @latest; v5->v6 migration guide added;
CHANGELOG cut as [6.0.0]. Blog posts left at their historical versions.

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-06-18 11:55:35 +01:00

226 行
4.3 KiB
Go

package template
var (
CrudProtoSRV = `syntax = "proto3";
package {{dehyphen .Alias}};
option go_package = "./proto;{{dehyphen .Alias}}";
service {{title .Alias}} {
rpc Create(CreateRequest) returns (CreateResponse) {}
rpc Read(ReadRequest) returns (ReadResponse) {}
rpc Update(UpdateRequest) returns (UpdateResponse) {}
rpc Delete(DeleteRequest) returns (DeleteResponse) {}
rpc List(ListRequest) returns (ListResponse) {}
}
message {{title .Alias}}Record {
string id = 1;
string name = 2;
string email = 3;
string phone = 4;
string company = 5;
int64 created = 6;
int64 updated = 7;
}
message CreateRequest {
string name = 1;
string email = 2;
string phone = 3;
string company = 4;
}
message CreateResponse {
{{title .Alias}}Record record = 1;
}
message ReadRequest {
string id = 1;
}
message ReadResponse {
{{title .Alias}}Record record = 1;
}
message UpdateRequest {
string id = 1;
string name = 2;
string email = 3;
string phone = 4;
string company = 5;
}
message UpdateResponse {
{{title .Alias}}Record record = 1;
}
message DeleteRequest {
string id = 1;
}
message DeleteResponse {
bool deleted = 1;
}
message ListRequest {
int64 limit = 1;
int64 offset = 2;
}
message ListResponse {
repeated {{title .Alias}}Record records = 1;
int64 total = 2;
}
`
CrudHandlerSRV = `package handler
import (
"context"
"fmt"
"sort"
"sync"
"time"
"github.com/google/uuid"
log "go-micro.dev/v6/logger"
pb "{{.Dir}}/proto"
)
type {{title .Alias}} struct {
mu sync.RWMutex
records map[string]*pb.{{title .Alias}}Record
}
func New() *{{title .Alias}} {
return &{{title .Alias}}{
records: make(map[string]*pb.{{title .Alias}}Record),
}
}
// Create adds a new record and returns it with a generated ID.
//
// @example {"name": "Alice Smith", "email": "alice@example.com", "phone": "+1-555-0100", "company": "Acme Inc"}
func (h *{{title .Alias}}) Create(ctx context.Context, req *pb.CreateRequest, rsp *pb.CreateResponse) error {
log.Infof("Creating record: %s", req.Name)
now := time.Now().Unix()
record := &pb.{{title .Alias}}Record{
Id: uuid.New().String(),
Name: req.Name,
Email: req.Email,
Phone: req.Phone,
Company: req.Company,
Created: now,
Updated: now,
}
h.mu.Lock()
h.records[record.Id] = record
h.mu.Unlock()
rsp.Record = record
return nil
}
// Read retrieves a record by ID.
//
// @example {"id": "some-uuid"}
func (h *{{title .Alias}}) Read(ctx context.Context, req *pb.ReadRequest, rsp *pb.ReadResponse) error {
h.mu.RLock()
record, ok := h.records[req.Id]
h.mu.RUnlock()
if !ok {
return fmt.Errorf("record %s not found", req.Id)
}
rsp.Record = record
return nil
}
// Update modifies an existing record. Only non-empty fields are updated.
//
// @example {"id": "some-uuid", "name": "Alice Johnson", "email": "alice.j@example.com"}
func (h *{{title .Alias}}) Update(ctx context.Context, req *pb.UpdateRequest, rsp *pb.UpdateResponse) error {
h.mu.Lock()
defer h.mu.Unlock()
record, ok := h.records[req.Id]
if !ok {
return fmt.Errorf("record %s not found", req.Id)
}
if req.Name != "" {
record.Name = req.Name
}
if req.Email != "" {
record.Email = req.Email
}
if req.Phone != "" {
record.Phone = req.Phone
}
if req.Company != "" {
record.Company = req.Company
}
record.Updated = time.Now().Unix()
rsp.Record = record
return nil
}
// Delete removes a record by ID.
//
// @example {"id": "some-uuid"}
func (h *{{title .Alias}}) Delete(ctx context.Context, req *pb.DeleteRequest, rsp *pb.DeleteResponse) error {
h.mu.Lock()
_, ok := h.records[req.Id]
if ok {
delete(h.records, req.Id)
}
h.mu.Unlock()
rsp.Deleted = ok
return nil
}
// List returns all records with optional pagination.
//
// @example {"limit": 10, "offset": 0}
func (h *{{title .Alias}}) List(ctx context.Context, req *pb.ListRequest, rsp *pb.ListResponse) error {
h.mu.RLock()
defer h.mu.RUnlock()
all := make([]*pb.{{title .Alias}}Record, 0, len(h.records))
for _, r := range h.records {
all = append(all, r)
}
sort.Slice(all, func(i, j int) bool {
return all[i].Created > all[j].Created
})
rsp.Total = int64(len(all))
offset := int(req.Offset)
if offset > len(all) {
offset = len(all)
}
limit := int(req.Limit)
if limit <= 0 {
limit = 20
}
end := offset + limit
if end > len(all) {
end = len(all)
}
rsp.Records = all[offset:end]
return nil
}
`
)