@@ -18,10 +18,9 @@ package gs
1818
1919import (
2020 "context"
21- "fmt"
2221 "reflect"
23- "strings"
2422
23+ "github.com/go-spring/log"
2524 "github.com/go-spring/spring-core/conf"
2625 "github.com/go-spring/spring-core/gs/internal/gs"
2726 "github.com/go-spring/spring-core/gs/internal/gs_app"
@@ -30,7 +29,6 @@ import (
3029 "github.com/go-spring/spring-core/gs/internal/gs_cond"
3130 "github.com/go-spring/spring-core/gs/internal/gs_conf"
3231 "github.com/go-spring/spring-core/gs/internal/gs_dync"
33- "github.com/go-spring/spring-core/log"
3432)
3533
3634const (
@@ -175,7 +173,7 @@ func BeanSelectorFor[T any](name ...string) BeanSelector {
175173// Property sets a system property.
176174func Property (key string , val string ) {
177175 if err := gs_conf .SysConf .Set (key , val ); err != nil {
178- log .Errorf (context .Background (), log .TagGS , "failed to set property key=%s, err=%v" , key , err )
176+ log .Errorf (context .Background (), log .TagApp , "failed to set property key=%s, err=%v" , key , err )
179177 }
180178}
181179
@@ -212,48 +210,12 @@ func FuncJob(fn func(ctx context.Context) error) *RegisteredBean {
212210 return Object (funcJob (fn )).AsJob ().Caller (1 )
213211}
214212
215- type AppStarter struct {}
216-
217213// Web enables or disables the built-in web server.
218214func Web (enable bool ) * AppStarter {
219215 EnableSimpleHttpServer (enable )
220216 return & AppStarter {}
221217}
222218
223- // Run runs the app and waits for an interrupt signal to exit.
224- func (s * AppStarter ) Run () {
225- s .RunWith (nil )
226- }
227-
228- // RunWith runs the app with a given function and waits for an interrupt signal to exit.
229- func (s * AppStarter ) RunWith (fn func (ctx context.Context ) error ) {
230- var err error
231- defer func () {
232- if err != nil {
233- log .Errorf (context .Background (), log .TagGS , "app run failed: %v" , err )
234- }
235- }()
236- printBanner ()
237- if err = B .(* gs_app.BootImpl ).Run (); err != nil {
238- return
239- }
240- B = nil
241- err = gs_app .GS .RunWith (fn )
242- }
243-
244- // RunAsync runs the app asynchronously and returns a function to stop the app.
245- func (s * AppStarter ) RunAsync () (func (), error ) {
246- printBanner ()
247- if err := B .(* gs_app.BootImpl ).Run (); err != nil {
248- return nil , err
249- }
250- B = nil
251- if err := gs_app .GS .Start (); err != nil {
252- return nil , err
253- }
254- return func () { gs_app .GS .Stop () }, nil
255- }
256-
257219// Run runs the app and waits for an interrupt signal to exit.
258220func Run () {
259221 new (AppStarter ).Run ()
@@ -321,50 +283,3 @@ func RefreshProperties() error {
321283 }
322284 return gs_app .GS .C .RefreshProperties (p )
323285}
324-
325- /********************************** banner ***********************************/
326-
327- var appBanner = `
328- ____ ___ ____ ____ ____ ___ _ _ ____
329- / ___| / _ \ / ___| | _ \ | _ \ |_ _| | \ | | / ___|
330- | | _ | | | | _____ \___ \ | |_) | | |_) | | | | \| | | | _
331- | |_| | | |_| | |_____| ___) | | __/ | _ < | | | |\ | | |_| |
332- \____| \___/ |____/ |_| |_| \_\ |___| |_| \_| \____|
333- `
334-
335- // Banner sets a custom app banner.
336- func Banner (banner string ) {
337- appBanner = banner
338- }
339-
340- // printBanner prints the app banner.
341- func printBanner () {
342- if len (appBanner ) == 0 {
343- return
344- }
345-
346- if appBanner [0 ] != '\n' {
347- fmt .Println ()
348- }
349-
350- maxLength := 0
351- for s := range strings .SplitSeq (appBanner , "\n " ) {
352- fmt .Printf ("\x1b [36m%s\x1b [0m\n " , s ) // CYAN
353- if len (s ) > maxLength {
354- maxLength = len (s )
355- }
356- }
357-
358- if appBanner [len (appBanner )- 1 ] != '\n' {
359- fmt .Println ()
360- }
361-
362- var padding []byte
363- if n := (maxLength - len (Version )) / 2 ; n > 0 {
364- padding = make ([]byte , n )
365- for i := range padding {
366- padding [i ] = ' '
367- }
368- }
369- fmt .Println (string (padding ) + Version + "\n " )
370- }
0 commit comments