-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: refactor scan package dependencies
- Add `github.com/blackhorseya/ryze/app/infra/transports/httpx` to imports in `adpater/block/scan/impl.go` - Update `NewRestful` function signature in `adpater/block/scan/impl.go` - Add `github.com/blackhorseya/ryze/pkg/contextx` to imports in `adpater/block/scan/impl.go` - Add `go.uber.org/zap` to imports in `adpater/block/scan/impl.go` - Add `main_test.go` file with tests for `scan` package - Add `github.com/blackhorseya/ryze/app/infra/transports/httpx` to imports in `adpater/block/scan/wire.go` - Update `New` function in `adpater/block/scan/wire.go` - Add `github.com/blackhorseya/ryze/app/infra/transports/httpx` to imports in `adpater/block/scan/wire_gen.go` - Update `New` function in `adpater/block/scan/wire_gen.go` - Add `github.com/blackhorseya/ryze/app/infra/transports/httpx` to imports in `adpater/block/wirex/injector.go` - Add `app/infra/transports/httpx` to imports in `app/infra/configx/app.go` - Add `app/infra/transports/httpx` to imports in ` Signed-off-by: Sean Zheng <[email protected]>
- Loading branch information
1 parent
261856c
commit c7f9489
Showing
7 changed files
with
117 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,67 @@ | ||
package scan | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/blackhorseya/ryze/adpater/block/wirex" | ||
"github.com/blackhorseya/ryze/app/infra/transports/httpx" | ||
"github.com/blackhorseya/ryze/pkg/adapterx" | ||
"github.com/blackhorseya/ryze/pkg/contextx" | ||
"github.com/gin-gonic/gin" | ||
"go.uber.org/zap" | ||
) | ||
|
||
type restful struct { | ||
injector *wirex.Injector | ||
server *httpx.Server | ||
} | ||
|
||
// NewRestful is used to create a new adapterx.Restful | ||
func NewRestful(injector *wirex.Injector) adapterx.Restful { | ||
func NewRestful(injector *wirex.Injector, server *httpx.Server) adapterx.Restful { | ||
return &restful{ | ||
injector: injector, | ||
server: server, | ||
} | ||
} | ||
|
||
func (i *restful) Start() error { | ||
// TODO implement me | ||
panic("implement me") | ||
ctx := contextx.Background() | ||
|
||
err := i.InitRouting() | ||
if err != nil { | ||
ctx.Error("Failed to init routing", zap.Error(err)) | ||
return err | ||
} | ||
|
||
err = i.server.Start(ctx) | ||
if err != nil { | ||
ctx.Error("Failed to start server", zap.Error(err)) | ||
return err | ||
} | ||
|
||
swaggerURL := fmt.Sprintf("http://localhost:%d/api/docs/index.html", i.injector.A.HTTP.Port) | ||
ctx.Info("start restful server", zap.String("swagger_url", swaggerURL)) | ||
|
||
return nil | ||
} | ||
|
||
func (i *restful) AwaitSignal() error { | ||
// TODO implement me | ||
panic("implement me") | ||
ctx := contextx.Background() | ||
ctx.Info("receive signal to stop server") | ||
|
||
if err := i.server.Stop(ctx); err != nil { | ||
ctx.Error("Failed to stop server", zap.Error(err)) | ||
return fmt.Errorf("failed to stop server: %w", err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (i *restful) InitRouting() error { | ||
// TODO implement me | ||
panic("implement me") | ||
// TODO: 2024/7/27|sean|implement me | ||
return nil | ||
} | ||
|
||
func (i *restful) GetRouter() *gin.Engine { | ||
// TODO implement me | ||
panic("implement me") | ||
return i.server.Router | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
//go:build external | ||
|
||
package scan | ||
|
||
import ( | ||
"os" | ||
"os/signal" | ||
"syscall" | ||
"testing" | ||
|
||
"github.com/spf13/viper" | ||
) | ||
|
||
func TestRun(t *testing.T) { | ||
restful, err := New(viper.New()) | ||
if err != nil { | ||
t.Fatalf("New() error = %v", err) | ||
} | ||
|
||
err = restful.Start() | ||
if err != nil { | ||
t.Fatalf("Start() error = %v", err) | ||
} | ||
|
||
signalChan := make(chan os.Signal, 1) | ||
signal.Notify(signalChan, syscall.SIGTERM, syscall.SIGINT) | ||
|
||
<-signalChan | ||
|
||
err = restful.AwaitSignal() | ||
if err != nil { | ||
t.Fatalf("AwaitSignal() error = %v", err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package configx | ||
|
||
import ( | ||
"github.com/blackhorseya/ryze/app/infra/transports/httpx" | ||
) | ||
|
||
// Application is the application configuration. | ||
type Application struct { | ||
HTTP httpx.Options `json:"http" yaml:"http"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters