go-woo / protoc-gen-echo

Generate Echo backend code

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

JWT scope detection issue

tburschka opened this issue · comments

Hi,

i try to run this, but i get always an issue due to jwt scope detection:

syntax = "proto3";

package greet.v1;

import "google/api/annotations.proto";
import "google/api/client.proto";

option go_package = "example/proto/gen/go/greet/v1;greet";


message GreetRequest {
  string person = 1;
}

message GreetResponse {
  string greeting = 1;
}

service GreetService {
  option (google.api.default_host) = "/";

  rpc Greet(GreetRequest) returns (GreetResponse) {
    option (google.api.http) = {
      get: "/hello/{person}"
    };
  }
}

Generated code:

Failure: plugin echo: greet/v1/greet_router.pb.go: unparsable Go source: 31:3: expected statement, found ':='
    1   // Code generated by protoc-gen-echo. DO NOT EDIT.
    2   // versions:
    3   // - protoc-gen-echo v0.1.1
    4   // - protoc  (unknown)
    5   // source: greet/v1/greet.proto
    6   
    7   package greet
    8   
    9   
   10   import (
   11           "net/http"
   12           "os"
   13   
   14           "github.com/go-woo/protoc-gen-echo/runtime"
   15           "github.com/labstack/echo/v4"
   16           "github.com/labstack/echo/v4/middleware"
   17   )
   18   
   19   
   20   
   21   func RegisterGreetServiceRouter(e *echo.Echo) {
   22           jwtKey := "dangerous"
   23           if os.Getenv("JWTKEY") != "" {
   24                   jwtKey = os.Getenv("JWTKEY")
   25           }
   26           config := middleware.JWTConfig{
   27                   Claims:     &runtime.JwtCustomClaims{},
   28                   SigningKey: []byte(jwtKey),
   29           }
   30           
   31            := e.Group("/")
   32           .Use(middleware.JWTWithConfig(config))
   33           
   34           .GET("/hello/:person", _GreetService_Greet0_HTTP_Handler)
   35   }
   36   
   37   func _GreetService_Greet0_HTTP_Handler(c echo.Context) error {
   38           var req *GreetRequest = new(GreetRequest)
   39           uv := c.QueryParams()
   40           return runtime.BindValues(req, uv)
   41           reply, err := GreetServiceGreetBusinessHandler(req, c)
   42           if err != nil {
   43                   return err
   44           }
   45           return c.JSON(http.StatusOK, &reply)
   46   }

I use buf to generate these files:

buf.yaml

version: v1
breaking:
  use:
    - FILE
lint:
  use:
    - DEFAULT
deps:
  - buf.build/googleapis/googleapis

buf.gen.yaml

version: v1
plugins:
  - name: go
    out: gen/go
    opt: paths=source_relative
  - name: go-grpc
    out: gen/go
    opt: paths=source_relative
  - name: echo
    out: gen/go/echo
    opt: paths=source_relative

@go-woo Any news here?

image
在http.go 文件这里,需要判断是否为空字符串,如果为空,可以命名为 rootRoute