-
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.
- Loading branch information
Showing
23 changed files
with
1,415 additions
and
4 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
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 @@ | ||
*.log |
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,72 @@ | ||
// Package main contains a go-orb client which uses a fake login server. | ||
package main | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
|
||
"github.com/go-orb/go-orb/client" | ||
"github.com/go-orb/go-orb/log" | ||
"github.com/go-orb/go-orb/types" | ||
"github.com/go-orb/go-orb/util/metadata" | ||
"google.golang.org/protobuf/types/known/emptypb" | ||
|
||
// Own imports. | ||
authproto "github.com/go-orb/examples/rest/auth/proto/auth" | ||
|
||
_ "github.com/go-orb/plugins/codecs/json" | ||
_ "github.com/go-orb/plugins/codecs/proto" | ||
_ "github.com/go-orb/plugins/log/slog" | ||
|
||
_ "github.com/go-orb/plugins-experimental/registry/mdns" | ||
|
||
_ "github.com/go-orb/plugins/client/middleware/log" | ||
_ "github.com/go-orb/plugins/client/orb" | ||
_ "github.com/go-orb/plugins/client/orb/transport/drpc" | ||
) | ||
|
||
func runner( | ||
logger log.Logger, | ||
clientWire client.Type, | ||
) error { | ||
// Create a request. | ||
req := &authproto.LoginRequest{Username: "someUserName", Password: "changeMe"} | ||
|
||
// Run the query. | ||
authClient := authproto.NewAuthClient(clientWire) | ||
tokenResp, err := authClient.Login(context.Background(), "orb.examples.rest.auth.server", req) | ||
|
||
if err != nil { | ||
logger.Error("while requesting", "error", err) | ||
return err | ||
} | ||
|
||
ctx, md := metadata.WithOutgoing(context.Background()) | ||
md["authorization"] = "Bearer " + tokenResp.GetToken() | ||
|
||
introspectResponse, err := authClient.Introspect(ctx, "orb.examples.rest.auth.server", &emptypb.Empty{}) | ||
if err != nil { | ||
logger.Error("while requesting", "error", err) | ||
return err | ||
} | ||
|
||
if introspectResponse.GetUsername() != req.GetUsername() { | ||
logger.Error("while requesting", "expected", req.GetUsername(), "got", introspectResponse.GetUsername()) | ||
return errors.New("bad response") | ||
} | ||
|
||
logger.Info("all good") | ||
|
||
return nil | ||
} | ||
|
||
func main() { | ||
var ( | ||
serviceName = types.ServiceName("orb.examples.rest.auth.client") | ||
serviceVersion = types.ServiceVersion("v0.0.1") | ||
) | ||
|
||
if _, err := run(serviceName, serviceVersion, runner); err != nil { | ||
log.Error("while running", "err", 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
//go:build wireinject | ||
// +build wireinject | ||
|
||
package main | ||
|
||
import ( | ||
"context" | ||
"os" | ||
|
||
"github.com/go-orb/go-orb/client" | ||
"github.com/go-orb/go-orb/log" | ||
"github.com/go-orb/go-orb/registry" | ||
"github.com/go-orb/go-orb/types" | ||
"github.com/go-orb/wire" | ||
) | ||
|
||
// provideLoggerOpts returns the logger options. | ||
func provideLoggerOpts() ([]log.Option, error) { | ||
return []log.Option{log.WithLevel("TRACE")}, nil | ||
} | ||
|
||
func provideClientOpts() ([]client.Option, error) { | ||
return []client.Option{client.WithClientMiddleware(client.MiddlewareConfig{Name: "log"})}, nil | ||
} | ||
|
||
// provideComponents creates a slice of components out of the arguments. | ||
func provideComponents( | ||
logger log.Logger, | ||
client client.Type, | ||
) ([]types.Component, error) { | ||
components := []types.Component{} | ||
components = append(components, logger) | ||
components = append(components, client) | ||
|
||
return components, nil | ||
} | ||
|
||
type wireRunResult string | ||
|
||
type wireRunCallback func( | ||
logger log.Logger, | ||
client client.Type, | ||
) error | ||
|
||
func wireRun( | ||
_ types.ServiceName, | ||
components []types.Component, | ||
_ types.ConfigData, | ||
logger log.Logger, | ||
client client.Type, | ||
cb wireRunCallback, | ||
) (wireRunResult, error) { | ||
// | ||
// Orb start | ||
for _, c := range components { | ||
err := c.Start() | ||
if err != nil { | ||
log.Error("Failed to start", err, "component", c.Type()) | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
// | ||
// Actual code | ||
runErr := cb(logger, client) | ||
|
||
// | ||
// Orb shutdown. | ||
ctx := context.Background() | ||
|
||
for k := range components { | ||
c := components[len(components)-1-k] | ||
|
||
err := c.Stop(ctx) | ||
if err != nil { | ||
log.Error("Failed to stop", err, "component", c.Type()) | ||
} | ||
} | ||
|
||
return "", runErr | ||
} | ||
|
||
// run combines everything above and | ||
func run( | ||
serviceName types.ServiceName, | ||
serviceVersion types.ServiceVersion, | ||
cb wireRunCallback, | ||
) (wireRunResult, error) { | ||
panic(wire.Build( | ||
wire.Value([]types.ConfigData{}), | ||
provideLoggerOpts, | ||
log.Provide, | ||
wire.Value([]registry.Option{}), | ||
registry.Provide, | ||
provideClientOpts, | ||
client.Provide, | ||
provideComponents, | ||
wireRun, | ||
)) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.