micro--go-micro
669481224c
* feat(cli): add CRUD, pub/sub, and API gateway templates for micro new
Add --template flag to 'micro new' with three preset templates:
- crud: CRUD service with Create/Read/Update/Delete/List, in-memory
store with sync.RWMutex, UUID generation, pagination, and doc
comments with @example tags for MCP tool discovery.
- pubsub: Event-driven service with Publish/Stats RPCs and a
Subscribe method that hooks into the broker. Includes event
types with ID, type, source, data, and timestamp.
- api: API gateway service with Health and Endpoint RPCs, an
internal HTTP route table, and a response recorder for
proxying requests through RPC.
All templates include MCP-ready doc comments and work with
--no-mcp. The default template (no flag) is unchanged.
Usage:
micro new myservice --template crud
micro new myservice --template pubsub
micro new myservice --template api
* fix(ai): update Atlas Cloud provider to use actual API formats
Fix the Atlas Cloud image generation to use their real async API:
POST /api/v1/model/generateImage → poll /api/v1/model/prediction/{id}
instead of the OpenAI-compatible endpoint which doesn't exist.
Add Quality and OutputFormat fields to ai.ImageRequest for
provider-specific image parameters.
Update default text model from llama-3.3-70b (doesn't exist) to
deepseek-ai/DeepSeek-V3-0324 (their flagship model). Update
default image model to openai/gpt-image-2/text-to-image.
* feat(website): add AI-generated images to landing page, docs, and blog
Generate 5 images via Atlas Cloud's image API (gpt-image-2) to
elevate the website experience:
- hero.png: microservices network graph for landing page
- architecture.png: registry + broker architecture diagram
- mcp-agent.png: AI agent calling services via MCP
- developer-experience.png: terminal showing micro run/chat
- blog-atlas.png: Atlas Cloud unified API illustration
Add visual sections to the landing page with architecture,
MCP integration, and developer experience showcases. Add
images to docs index, MCP docs, and Atlas Cloud blog post.
All images resized to 1200px wide and optimized for web.
Generated using Atlas Cloud sponsor credits.
* feat(website): redesign landing page and add images to docs
Redesign the landing page from a centered card layout to a
full-width modern site with:
- Top navigation bar
- Hero section with gradient background and CTA buttons
- Full-width image showcase sections
- Two-column layout for architecture, MCP, and DX sections
- Feature grid with 6 capabilities
- Footer with links
- Responsive breakpoints for mobile
Generate 3 more images via Atlas Cloud for docs:
- getting-started.png for the getting started guide
- deployment.png for the deployment guide
- data-model.png for the data model docs
Add images to getting-started.md, model.md, and deployment.md.
---------
Co-authored-by: Claude <noreply@anthropic.com>
123 行
2.7 KiB
Go
123 行
2.7 KiB
Go
package template
|
|
|
|
var (
|
|
ApiProtoSRV = `syntax = "proto3";
|
|
|
|
package {{dehyphen .Alias}};
|
|
|
|
option go_package = "./proto;{{dehyphen .Alias}}";
|
|
|
|
service {{title .Alias}} {
|
|
rpc Health(HealthRequest) returns (HealthResponse) {}
|
|
rpc Endpoint(EndpointRequest) returns (EndpointResponse) {}
|
|
}
|
|
|
|
message HealthRequest {}
|
|
|
|
message HealthResponse {
|
|
string status = 1;
|
|
int64 uptime = 2;
|
|
}
|
|
|
|
message EndpointRequest {
|
|
string method = 1;
|
|
string path = 2;
|
|
string body = 3;
|
|
map<string, string> headers = 4;
|
|
}
|
|
|
|
message EndpointResponse {
|
|
int32 status_code = 1;
|
|
string body = 2;
|
|
map<string, string> headers = 3;
|
|
}
|
|
`
|
|
|
|
ApiHandlerSRV = `package handler
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"net/http"
|
|
"time"
|
|
|
|
log "go-micro.dev/v5/logger"
|
|
|
|
pb "{{.Dir}}/proto"
|
|
)
|
|
|
|
type {{title .Alias}} struct {
|
|
started time.Time
|
|
routes map[string]http.HandlerFunc
|
|
}
|
|
|
|
func New() *{{title .Alias}} {
|
|
h := &{{title .Alias}}{
|
|
started: time.Now(),
|
|
routes: make(map[string]http.HandlerFunc),
|
|
}
|
|
h.registerRoutes()
|
|
return h
|
|
}
|
|
|
|
func (h *{{title .Alias}}) registerRoutes() {
|
|
h.routes["GET /hello"] = func(w http.ResponseWriter, r *http.Request) {
|
|
name := r.URL.Query().Get("name")
|
|
if name == "" {
|
|
name = "World"
|
|
}
|
|
json.NewEncoder(w).Encode(map[string]string{
|
|
"message": fmt.Sprintf("Hello %s", name),
|
|
})
|
|
}
|
|
}
|
|
|
|
// Health returns the service health status and uptime.
|
|
//
|
|
// @example {}
|
|
func (h *{{title .Alias}}) Health(ctx context.Context, req *pb.HealthRequest, rsp *pb.HealthResponse) error {
|
|
rsp.Status = "ok"
|
|
rsp.Uptime = int64(time.Since(h.started).Seconds())
|
|
return nil
|
|
}
|
|
|
|
// Endpoint handles proxied HTTP requests. The method and path fields
|
|
// select the route; body and headers are forwarded.
|
|
//
|
|
// @example {"method": "GET", "path": "/hello", "body": "", "headers": {}}
|
|
func (h *{{title .Alias}}) Endpoint(ctx context.Context, req *pb.EndpointRequest, rsp *pb.EndpointResponse) error {
|
|
key := fmt.Sprintf("%s %s", req.Method, req.Path)
|
|
handler, ok := h.routes[key]
|
|
if !ok {
|
|
log.Infof("Route not found: %s", key)
|
|
rsp.StatusCode = 404
|
|
rsp.Body = ` + "`" + `{"error":"not found"}` + "`" + `
|
|
return nil
|
|
}
|
|
|
|
rec := &responseRecorder{headers: make(map[string]string), statusCode: 200}
|
|
fakeReq, _ := http.NewRequestWithContext(ctx, req.Method, req.Path, nil)
|
|
handler(rec, fakeReq)
|
|
|
|
rsp.StatusCode = int32(rec.statusCode)
|
|
rsp.Body = rec.body
|
|
rsp.Headers = rec.headers
|
|
return nil
|
|
}
|
|
|
|
type responseRecorder struct {
|
|
headers map[string]string
|
|
body string
|
|
statusCode int
|
|
}
|
|
|
|
func (r *responseRecorder) Header() http.Header { return http.Header{} }
|
|
func (r *responseRecorder) WriteHeader(statusCode int) { r.statusCode = statusCode }
|
|
func (r *responseRecorder) Write(b []byte) (int, error) {
|
|
r.body = string(b)
|
|
return len(b), nil
|
|
}
|
|
`
|
|
)
|