micro--go-micro
c7657f73f4
goreleaser / goreleaser (push) Has been cancelled
* 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>
73 行
2.1 KiB
Go
73 行
2.1 KiB
Go
// Package cliutil contains methods used across all cli commands
|
|
// @todo: get rid of os.Exits and use errors instread
|
|
package util
|
|
|
|
import (
|
|
"fmt"
|
|
"regexp"
|
|
"strings"
|
|
|
|
"github.com/urfave/cli/v2"
|
|
merrors "go-micro.dev/v6/errors"
|
|
)
|
|
|
|
type Exec func(*cli.Context, []string) ([]byte, error)
|
|
|
|
func Print(e Exec) func(*cli.Context) error {
|
|
return func(c *cli.Context) error {
|
|
rsp, err := e(c, c.Args().Slice())
|
|
if err != nil {
|
|
return CliError(err)
|
|
}
|
|
if len(rsp) > 0 {
|
|
fmt.Printf("%s\n", string(rsp))
|
|
}
|
|
return nil
|
|
}
|
|
}
|
|
|
|
// CliError returns a user friendly message from error. If we can't determine a good one returns an error with code 128
|
|
func CliError(err error) cli.ExitCoder {
|
|
if err == nil {
|
|
return nil
|
|
}
|
|
// if it's already a cli.ExitCoder we use this
|
|
cerr, ok := err.(cli.ExitCoder)
|
|
if ok {
|
|
return cerr
|
|
}
|
|
|
|
// grpc errors
|
|
if mname := regexp.MustCompile(`malformed method name: \\?"(\w+)\\?"`).FindStringSubmatch(err.Error()); len(mname) > 0 {
|
|
return cli.Exit(fmt.Sprintf(`Method name "%s" invalid format. Expecting service.endpoint`, mname[1]), 3)
|
|
}
|
|
if service := regexp.MustCompile(`service ([\w\.]+): route not found`).FindStringSubmatch(err.Error()); len(service) > 0 {
|
|
return cli.Exit(fmt.Sprintf(`Service "%s" not found`, service[1]), 4)
|
|
}
|
|
if service := regexp.MustCompile(`unknown service ([\w\.]+)`).FindStringSubmatch(err.Error()); len(service) > 0 {
|
|
if strings.Contains(service[0], ".") {
|
|
return cli.Exit(fmt.Sprintf(`Service method "%s" not found`, service[1]), 5)
|
|
}
|
|
return cli.Exit(fmt.Sprintf(`Service "%s" not found`, service[1]), 5)
|
|
}
|
|
if address := regexp.MustCompile(`Error while dialing dial tcp.*?([\w]+\.[\w:\.]+): `).FindStringSubmatch(err.Error()); len(address) > 0 {
|
|
return cli.Exit(fmt.Sprintf(`Failed to connect to micro server at %s`, address[1]), 4)
|
|
}
|
|
|
|
merr, ok := err.(*merrors.Error)
|
|
if !ok {
|
|
return cli.Exit(err, 128)
|
|
}
|
|
|
|
switch merr.Code {
|
|
case 408:
|
|
return cli.Exit("Request timed out", 1)
|
|
case 401:
|
|
// TODO check if not signed in, prompt to sign in
|
|
return cli.Exit("Not authorized to perform this request", 2)
|
|
}
|
|
|
|
// fallback to using the detail from the merr
|
|
return cli.Exit(merr.Detail, 127)
|
|
}
|