From e584ccc86dd0713f6b8201a6a921ac7a66825c8c Mon Sep 17 00:00:00 2001 From: "shijinyu.7" Date: Wed, 7 Jan 2026 20:13:57 +0800 Subject: [PATCH] feat: add the apps start url logs --- apps/a2a_app/app.go | 11 ++++++--- apps/agentkit_server_app/app.go | 7 ++++-- apps/basic_app.go | 5 ++++ apps/looger.go | 44 --------------------------------- apps/simple_app/app.go | 6 +++-- 5 files changed, 22 insertions(+), 51 deletions(-) delete mode 100644 apps/looger.go diff --git a/apps/a2a_app/app.go b/apps/a2a_app/app.go index 2bfb0c1..b87caba 100644 --- a/apps/a2a_app/app.go +++ b/apps/a2a_app/app.go @@ -17,6 +17,7 @@ package a2a_app import ( "context" "fmt" + "log" "net/http" "net/url" @@ -25,6 +26,7 @@ import ( "github.com/gorilla/mux" "github.com/volcengine/veadk-go/apps" "google.golang.org/adk/cmd/launcher/web" + "google.golang.org/adk/cmd/launcher/web/a2a" "google.golang.org/adk/runner" "google.golang.org/adk/server/adka2a" "google.golang.org/adk/session" @@ -44,13 +46,12 @@ func (a *agentkitA2AServerApp) Run(ctx context.Context, config *apps.RunConfig) config.SessionService = session.InMemoryService() } + log.Printf("Web servers starts on %s", a.GetWebUrl()) err := a.SetupRouters(router, config) if err != nil { return fmt.Errorf("setup a2a routers failed: %w", err) } - apps.RoutesLog(router) - srv := http.Server{ Addr: fmt.Sprintf(":%v", fmt.Sprint(a.Port)), WriteTimeout: a.WriteTimeout, @@ -99,12 +100,16 @@ func (a *agentkitA2AServerApp) SetupRouters(router *mux.Router, config *apps.Run }) reqHandler := a2asrv.NewHandler(executor, config.A2AOptions...) router.Handle(apiPath, a2asrv.NewJSONRPCHandler(reqHandler)) + + a2aLauncher := a2a.NewLauncher() + a2aLauncher.UserMessage(a.GetWebUrl()+apiPath, log.Println) + return nil } func NewAgentkitA2AServerApp(config apps.ApiConfig) apps.BasicApp { return &agentkitA2AServerApp{ ApiConfig: config, - a2aAgentUrl: fmt.Sprintf("http://localhost:%v", config.Port), + a2aAgentUrl: config.GetWebUrl(), } } diff --git a/apps/agentkit_server_app/app.go b/apps/agentkit_server_app/app.go index be94700..274b751 100644 --- a/apps/agentkit_server_app/app.go +++ b/apps/agentkit_server_app/app.go @@ -17,6 +17,7 @@ package agentkit_server_app import ( "context" "fmt" + "log" "net/http" "github.com/gorilla/mux" @@ -47,13 +48,12 @@ func (a *agentkitServerApp) Run(ctx context.Context, config *apps.RunConfig) err config.SessionService = session.InMemoryService() } + log.Printf("Web servers starts on %s", a.GetWebUrl()) err := a.SetupRouters(router, config) if err != nil { return fmt.Errorf("setup agentkit server routers failed: %w", err) } - apps.RoutesLog(router) - srv := http.Server{ Addr: fmt.Sprintf(":%v", fmt.Sprint(a.Port)), WriteTimeout: a.WriteTimeout, @@ -129,5 +129,8 @@ func (a *agentkitServerApp) SetupRouters(router *mux.Router, config *apps.RunCon return fmt.Errorf("setup webui routers failed: %w", err) } + apiLauncher.UserMessage(a.GetWebUrl(), log.Println) + webuiLauncher.UserMessage(a.GetWebUrl(), log.Println) + return nil } diff --git a/apps/basic_app.go b/apps/basic_app.go index 170fb06..3faf9e1 100644 --- a/apps/basic_app.go +++ b/apps/basic_app.go @@ -16,6 +16,7 @@ package apps import ( "context" + "fmt" "time" "github.com/a2aproject/a2a-go/a2asrv" @@ -70,3 +71,7 @@ func (a *ApiConfig) SetReadTimeout(t int64) { func (a *ApiConfig) SetIdleTimeout(t int64) { a.IdleTimeout = time.Second * time.Duration(t) } + +func (a *ApiConfig) GetWebUrl() string { + return fmt.Sprintf("http://localhost:%d", a.Port) +} diff --git a/apps/looger.go b/apps/looger.go deleted file mode 100644 index 9289307..0000000 --- a/apps/looger.go +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright (c) 2025 Beijing Volcano Engine Technology Co., Ltd. and/or its affiliates. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package apps - -import ( - "log" - "strings" - - "github.com/gorilla/mux" -) - -func RoutesLog(router *mux.Router) { - log.Println("========================================") - log.Println("Registered API Routes:") - log.Println("========================================") - - _ = router.Walk(func(route *mux.Route, router *mux.Router, ancestors []*mux.Route) error { - path, _ := route.GetPathTemplate() - methods, _ := route.GetMethods() - - if path != "" { - methodStr := "ANY" - if len(methods) > 0 { - methodStr = strings.Join(methods, ", ") - } - log.Printf("%-8s %s", methodStr, path) - } - return nil - }) - - log.Println("========================================") -} diff --git a/apps/simple_app/app.go b/apps/simple_app/app.go index bd04b3a..6b6e897 100644 --- a/apps/simple_app/app.go +++ b/apps/simple_app/app.go @@ -87,19 +87,21 @@ func (app *agentkitSimpleApp) SetupRouters(router *mux.Router, config *apps.RunC router.NewRoute().Path("/invoke").Methods(http.MethodPost).HandlerFunc(app.newInvokeHandler()) router.NewRoute().Path("/health").Methods(http.MethodGet).HandlerFunc(app.newHealthHandler()) + log.Printf(" invoke: you can invoke agent using %s/invoke", app.GetWebUrl()) + log.Printf(" health: you can get health status using: %s/health", app.GetWebUrl()) + return nil } func (app *agentkitSimpleApp) Run(ctx context.Context, config *apps.RunConfig) error { router := web.BuildBaseRouter() + log.Printf("Web servers starts on %s", app.GetWebUrl()) err := app.SetupRouters(router, config) if err != nil { return fmt.Errorf("setup simple app router error: %w", err) } - apps.RoutesLog(router) - srv := http.Server{ Addr: fmt.Sprintf(":%s", fmt.Sprint(app.Port)), WriteTimeout: app.WriteTimeout,