Skip to content

Commit

Permalink
add auth prc server
Browse files Browse the repository at this point in the history
  • Loading branch information
xmcy0011 committed Aug 1, 2022
1 parent 8de6ad9 commit 2835a0e
Show file tree
Hide file tree
Showing 173 changed files with 13,408 additions and 2 deletions.
File renamed without changes.
30 changes: 30 additions & 0 deletions v2/api/apigw/api/apigw/apigw.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
syntax = "proto3";

package apigw.v1;

import "google/api/annotations.proto";

option go_package = "apigw/api/apigw/v1;v1";
option java_multiple_files = true;
option java_package = "dev.kratos.api.helloworld.v1";
option java_outer_classname = "HelloworldProtoV1";

// The greeting service definition.
service Greeter {
// Sends a greeting
rpc SayHello (HelloRequest) returns (HelloReply) {
option (google.api.http) = {
get: "/helloworld/{name}"
};
}
}

// The request message containing the user's name.
message HelloRequest {
string name = 1;
}

// The response message containing the greetings
message HelloReply {
string message = 1;
}
135 changes: 135 additions & 0 deletions v2/api/apigw/api/apigw/error_reason.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions v2/api/apigw/api/apigw/error_reason.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
syntax = "proto3";

package helloworld.v1;

option go_package = "apigw/api/helloworld/v1;v1";
option java_multiple_files = true;
option java_package = "helloworld.v1";
option objc_class_prefix = "APIHelloworldV1";

enum ErrorReason {
GEETER_UNSPECIFIED = 0;
USER_NOT_FOUND = 1;
}
84 changes: 84 additions & 0 deletions v2/api/apigw/cmd/apigw/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package main

import (
"flag"
"os"

"apigw/internal/conf"
"github.com/go-kratos/kratos/v2"
"github.com/go-kratos/kratos/v2/config"
"github.com/go-kratos/kratos/v2/config/file"
"github.com/go-kratos/kratos/v2/log"
"github.com/go-kratos/kratos/v2/middleware/tracing"
"github.com/go-kratos/kratos/v2/transport/grpc"
"github.com/go-kratos/kratos/v2/transport/http"
)

// go build -ldflags "-X main.Version=x.y.z"
var (
// Name is the name of the compiled software.
Name string
// Version is the version of the compiled software.
Version string
// flagconf is the config flag.
flagconf string

id, _ = os.Hostname()
)

func init() {
flag.StringVar(&flagconf, "conf", "../../configs", "config path, eg: -conf config.yaml")
}

func newApp(logger log.Logger, gs *grpc.Server, hs *http.Server) *kratos.App {
return kratos.New(
kratos.ID(id),
kratos.Name(Name),
kratos.Version(Version),
kratos.Metadata(map[string]string{}),
kratos.Logger(logger),
kratos.Server(
gs,
hs,
),
)
}

func main() {
flag.Parse()
logger := log.With(log.NewStdLogger(os.Stdout),
"ts", log.DefaultTimestamp,
"caller", log.DefaultCaller,
"service.id", id,
"service.name", Name,
"service.version", Version,
"trace.id", tracing.TraceID(),
"span.id", tracing.SpanID(),
)
c := config.New(
config.WithSource(
file.NewSource(flagconf),
),
)
defer c.Close()

if err := c.Load(); err != nil {
panic(err)
}

var bc conf.Bootstrap
if err := c.Scan(&bc); err != nil {
panic(err)
}

app, cleanup, err := wireApp(bc.Server, bc.Data, logger)
if err != nil {
panic(err)
}
defer cleanup()

// start and wait for stop signal
if err := app.Run(); err != nil {
panic(err)
}
}
21 changes: 21 additions & 0 deletions v2/api/apigw/cmd/apigw/wire.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// +build wireinject

// The build tag makes sure the stub is not built in the final build.

package main

import (
"apigw/internal/biz"
"apigw/internal/conf"
"apigw/internal/data"
"apigw/internal/server"
"apigw/internal/service"
"github.com/go-kratos/kratos/v2"
"github.com/go-kratos/kratos/v2/log"
"github.com/google/wire"
)

// wireApp init kratos application.
func wireApp(*conf.Server, *conf.Data, log.Logger) (*kratos.App, func(), error) {
panic(wire.Build(server.ProviderSet, data.ProviderSet, biz.ProviderSet, service.ProviderSet, newApp))
}
36 changes: 36 additions & 0 deletions v2/api/apigw/cmd/apigw/wire_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
29 changes: 29 additions & 0 deletions v2/api/apigw/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
module httpapi

go 1.17

require (
github.com/go-kratos/kratos/v2 v2.4.0
github.com/google/wire v0.5.0
google.golang.org/genproto v0.0.0-20220524023933-508584e28198
google.golang.org/grpc v1.46.2
google.golang.org/protobuf v1.28.0
)

require (
github.com/fsnotify/fsnotify v1.5.4 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-playground/form/v4 v4.2.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/gorilla/mux v1.8.0 // indirect
github.com/imdario/mergo v0.3.12 // indirect
go.opentelemetry.io/otel v1.7.0 // indirect
go.opentelemetry.io/otel/trace v1.7.0 // indirect
golang.org/x/net v0.0.0-20220520000938-2e3eb7b945c2 // indirect
golang.org/x/sync v0.0.0-20220513210516-0976fa681c29 // indirect
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect
golang.org/x/text v0.3.7 // indirect
gopkg.in/yaml.v3 v3.0.0 // indirect
)
Loading

0 comments on commit 2835a0e

Please sign in to comment.