micro--go-micro
1bb25d6e7f
* feat: add agent platform showcase and blog post Add a complete platform example (Users, Posts, Comments, Mail) that mirrors micro/blog, demonstrating how existing microservices become AI-accessible through MCP with zero code changes. Includes blog post "Your Microservices Are Already an AI Platform" walking through real agent workflows: signup, content creation, commenting, tagging, and cross-service messaging. https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc * refactor: rename handler types to drop redundant Service suffix UserService → Users, PostService → Posts, CommentService → Comments, MailService → Mail. Matches micro/blog naming convention. https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc * refactor: consolidate top-level directories, reduce framework bloat Move internal/non-public packages behind internal/ or into their parent packages where they belong: - deploy/ → gateway/mcp/deploy/ (Helm charts belong with the gateway) - profile/ → service/profile/ (preset plugin profiles are a service concern) - scripts/ → internal/scripts/ (install script is not public API) - test/ → internal/test/ (test harness is not public API) - util/ → internal/util/ (internal helpers shouldn't be imported externally) Also fixes CLAUDE.md merge conflict markers and updates project structure documentation. All import paths updated. Build and tests pass. https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc * refactor: redesign model package to match framework conventions Rename model.Database interface to model.Model (consistent with client.Client, server.Server, store.Store). Remove generics in favor of interface{}-based API with reflection. Key changes: - model.Model interface: Register once, CRUD infers table from type - DefaultModel + NewModel() + package-level convenience functions - Schema registered via Register(&User{}), no per-call schema passing - Memory implementation as default (in model package, like store) - memory/sqlite/postgres backends updated for new interface - protoc-gen-micro generates RegisterXModel() instead of generic factory - All docs, blog, and README updated https://claude.ai/code/session_01GkduEhcrqcG45rdfYh8dAc --------- Co-authored-by: Claude <noreply@anthropic.com>
133 行
2.6 KiB
Go
133 行
2.6 KiB
Go
package addr
|
|
|
|
import (
|
|
"github.com/stretchr/testify/assert"
|
|
"net"
|
|
"testing"
|
|
)
|
|
|
|
func TestIsLocal(t *testing.T) {
|
|
testData := []struct {
|
|
addr string
|
|
expect bool
|
|
}{
|
|
{"localhost", true},
|
|
{"localhost:8080", true},
|
|
{"127.0.0.1", true},
|
|
{"127.0.0.1:1001", true},
|
|
{"80.1.1.1", false},
|
|
}
|
|
|
|
for _, d := range testData {
|
|
res := IsLocal(d.addr)
|
|
if res != d.expect {
|
|
t.Fatalf("expected %t got %t", d.expect, res)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestExtractor(t *testing.T) {
|
|
testData := []struct {
|
|
addr string
|
|
expect string
|
|
parse bool
|
|
}{
|
|
{"127.0.0.1", "127.0.0.1", false},
|
|
{"10.0.0.1", "10.0.0.1", false},
|
|
{"", "", true},
|
|
{"0.0.0.0", "", true},
|
|
{"[::]", "", true},
|
|
}
|
|
|
|
for _, d := range testData {
|
|
addr, err := Extract(d.addr)
|
|
if err != nil {
|
|
t.Errorf("Unexpected error %v", err)
|
|
}
|
|
|
|
if d.parse {
|
|
ip := net.ParseIP(addr)
|
|
if ip == nil {
|
|
t.Error("Unexpected nil IP")
|
|
}
|
|
} else if addr != d.expect {
|
|
t.Errorf("Expected %s got %s", d.expect, addr)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestFindIP(t *testing.T) {
|
|
localhost, _ := net.ResolveIPAddr("ip", "127.0.0.1")
|
|
localhostIPv6, _ := net.ResolveIPAddr("ip", "::1")
|
|
privateIP, _ := net.ResolveIPAddr("ip", "10.0.0.1")
|
|
publicIP, _ := net.ResolveIPAddr("ip", "100.0.0.1")
|
|
publicIPv6, _ := net.ResolveIPAddr("ip", "2001:0db8:85a3:0000:0000:8a2e:0370:7334")
|
|
|
|
testCases := []struct {
|
|
addrs []net.Addr
|
|
ip net.IP
|
|
errMsg string
|
|
}{
|
|
{
|
|
addrs: []net.Addr{},
|
|
ip: nil,
|
|
errMsg: ErrIPNotFound.Error(),
|
|
},
|
|
{
|
|
addrs: []net.Addr{localhost},
|
|
ip: localhost.IP,
|
|
},
|
|
{
|
|
addrs: []net.Addr{localhost, localhostIPv6},
|
|
ip: localhost.IP,
|
|
},
|
|
{
|
|
addrs: []net.Addr{localhostIPv6},
|
|
ip: localhostIPv6.IP,
|
|
},
|
|
{
|
|
addrs: []net.Addr{privateIP, localhost},
|
|
ip: privateIP.IP,
|
|
},
|
|
{
|
|
addrs: []net.Addr{privateIP, publicIP, localhost},
|
|
ip: privateIP.IP,
|
|
},
|
|
{
|
|
addrs: []net.Addr{publicIP, privateIP, localhost},
|
|
ip: privateIP.IP,
|
|
},
|
|
{
|
|
addrs: []net.Addr{publicIP, localhost},
|
|
ip: publicIP.IP,
|
|
},
|
|
{
|
|
addrs: []net.Addr{publicIP, localhostIPv6},
|
|
ip: publicIP.IP,
|
|
},
|
|
{
|
|
addrs: []net.Addr{localhostIPv6, publicIP},
|
|
ip: publicIP.IP,
|
|
},
|
|
{
|
|
addrs: []net.Addr{localhostIPv6, publicIPv6, publicIP},
|
|
ip: publicIPv6.IP,
|
|
},
|
|
{
|
|
addrs: []net.Addr{publicIP, publicIPv6},
|
|
ip: publicIP.IP,
|
|
},
|
|
}
|
|
|
|
for _, tc := range testCases {
|
|
ip, err := findIP(tc.addrs)
|
|
if tc.errMsg == "" {
|
|
assert.Nil(t, err)
|
|
assert.Equal(t, tc.ip.String(), ip.String())
|
|
} else {
|
|
assert.NotNil(t, err)
|
|
assert.Equal(t, tc.errMsg, err.Error())
|
|
}
|
|
}
|
|
}
|