Skip to content

Commit

Permalink
Merge pull request #7 from loopholelabs/staging
Browse files Browse the repository at this point in the history
Release v0.6.0
  • Loading branch information
ShivanshVij authored Aug 24, 2022
2 parents d7a8465 + 8ebbd0d commit 331929e
Show file tree
Hide file tree
Showing 33 changed files with 181 additions and 805 deletions.
1 change: 1 addition & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Fixes # (issue)

- [ ] Bug fix (non-breaking change which fixes an issue) [title: 'fix:']
- [ ] New feature (non-breaking change which adds functionality) [title: 'feat:']
- [ ] Refactor (non-breaking code changes that do not add new functionality or break existing functionality) [title: 'refactor:']
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] This change requires a documentation update

Expand Down
3 changes: 2 additions & 1 deletion .trunk/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
*out
*logs
*logs
external
1 change: 1 addition & 0 deletions .trunk/plugins/trunk
2 changes: 1 addition & 1 deletion .trunk/trunk.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
version: 0.1
cli:
version: 0.15.0-beta
version: 0.16.1-beta
lint:
enabled:
- actionlint@1.6.13
Expand Down
14 changes: 13 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [v0.6.0] - 2022-08-24 (Beta)

## Changes

- Refactoring the generated code to use the [polyglot-go](https://github.com/loopholelabs/polyglot-go) library to generate message encode/decode functions. ([#3](https://github.com/loopholelabs/frpc-go/pull/3))

## Fixes

- Fixed an issue with the generated code that caused compilation issues when the names of two methods in different services
were the same ([#5](https://github.com/loopholelabs/frpc-go/issues/5))

## [v0.5.1] - 2022-07-20 (Beta)

## Fixes
Expand All @@ -16,6 +27,7 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

> Changelogs for [v0.5.0] and before can be found at https://github.com/loopholelabs/frisbee-go
[unreleased]: https://github.com/loopholelabs/frpc-go/compare/v0.5.1...HEAD
[unreleased]: https://github.com/loopholelabs/frpc-go/compare/v0.6.0...HEAD
[v0.6.0]: https://github.com/loopholelabs/frpc-go/releases/tag/v0.6.0
[v0.5.1]: https://github.com/loopholelabs/frpc-go/releases/tag/v0.5.1
[v0.5.0]: https://github.com/loopholelabs/frisbee-go/compare/v0.4.6...v0.5.0
10 changes: 3 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[![Tests](https://github.com/loopholelabs/frpc-go/actions/workflows/tests.yaml/badge.svg)](https://github.com/loopholelabs/frpc-go/actions/workflows/tests.yaml)

This is the [Go](http://golang.org) implementation of [fRPC](https://frpc.io), a high-performance RPC framework for
designed for performance and stability, and it uses [frisbee-go](https://frpc.io/frisbee) messaging framework under the hood.
designed for performance and stability, and it uses the [frisbee-go](https://github.com/loopholelabs/frisbee-go) messaging framework under the hood.

**This library requires Go1.18 or later.**

Expand All @@ -19,12 +19,8 @@ same is true for selected other new features explicitly marked as

Usage instructions and documentation for fRPC is available at [https://frpc.io/](https://frpc.io/).

The fRPC is still in very early **Alpha**. While it is functional and being used within other products
we're building at [Loophole Labs][loophomepage], the `proto3` spec has a myriad of edge-cases that make it difficult to
guarantee validity of generated RPC code without extensive real-world use.

That being said, as the library matures and usage of fRPC grows we'll be able to increase our testing
coverage and fix any edge cases and bugs. One of the major benefits to the RPC framework is that reading the generated code
fRPC is still in very early \*_Alpha_. There may be bug in the library that will be fixed
as the library matures and usage of fRPC grows. One of the major benefits to fRPC is that reading the generated code
is extremely straight forward, making it easy to debug potential issues down the line.

### Unsupported Features
Expand Down
11 changes: 10 additions & 1 deletion examples/echo/echo.proto
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,17 @@ service EchoService {
rpc Echo(Request) returns (Response);
}

service TestService {
rpc Echo(Request) returns (Response);
}

message Array {
repeated string value = 1;
}

message Request {
string Message = 1;
map <string, Array> metadata = 1;
string Message = 2;
}

message Response{
Expand Down
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@ module github.com/loopholelabs/frpc-go

go 1.18

require google.golang.org/protobuf v1.28.0
require (
github.com/loopholelabs/polyglot-go v0.4.0
google.golang.org/protobuf v1.28.0
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/loopholelabs/polyglot-go v0.4.0 h1:HavI5O6lMKF7urRgnVk+8vM4WqCpJGkH81dxLnhFGAA=
github.com/loopholelabs/polyglot-go v0.4.0/go.mod h1:Z0QiNv4KRuWjQWpUerMhmkvRh6ks1pYmEH4SGpG0EHQ=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
Expand Down
113 changes: 0 additions & 113 deletions internal/utils/utils.go

This file was deleted.

2 changes: 1 addition & 1 deletion internal/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
package version

const (
Version = "v0.5.1"
Version = "v0.6.0"
)
27 changes: 0 additions & 27 deletions pkg/generator/defaults.go

This file was deleted.

21 changes: 0 additions & 21 deletions pkg/generator/file.go

This file was deleted.

66 changes: 52 additions & 14 deletions pkg/generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
package generator

import (
"bytes"
"text/template"

"github.com/loopholelabs/frpc-go/internal/utils"
"github.com/loopholelabs/frpc-go/internal/version"
"github.com/loopholelabs/frpc-go/templates"
"github.com/loopholelabs/polyglot-go/pkg/generator"
"github.com/loopholelabs/polyglot-go/pkg/utils"
"google.golang.org/protobuf/compiler/protogen"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/pluginpb"
Expand All @@ -41,13 +43,6 @@ func init() {
"Counter": utils.Counter,
"FirstLowerCase": utils.FirstLowerCase,
"FirstLowerCaseName": utils.FirstLowerCaseName,
"FindValue": findValue,
"GetKind": getKind,
"GetLUTEncoder": getLUTEncoder,
"GetLUTDecoder": getLUTDecoder,
"GetEncodingFields": getEncodingFields,
"GetDecodingFields": getDecodingFields,
"GetKindLUT": getKindLUT,
"GetServerFields": getServerFields,
}).ParseFS(templates.FS, "*"))
}
Expand Down Expand Up @@ -76,11 +71,40 @@ func (g *Generator) Generate(req *pluginpb.CodeGeneratorRequest) (res *pluginpb.
return nil, err
}

var tplBuffer bytes.Buffer
if err := templ.ExecuteTemplate(&tplBuffer, "customEncode.templ", nil); err != nil {
return nil, err
}
customEncode := tplBuffer.String()
tplBuffer.Reset()

if err := templ.ExecuteTemplate(&tplBuffer, "customDecode.templ", nil); err != nil {
return nil, err
}
customDecode := tplBuffer.String()
tplBuffer.Reset()

if err := templ.ExecuteTemplate(&tplBuffer, "customFields.templ", nil); err != nil {
return nil, err
}
customFields := tplBuffer.String()

gen := generator.New()
gen.CustomEncode = func() string {
return customEncode
}
gen.CustomDecode = func() string {
return customDecode
}
gen.CustomFields = func() string {
return customFields
}

for _, f := range plugin.Files {
if !f.Generate {
continue
}
genFile := plugin.NewGeneratedFile(fileName(f.GeneratedFilenamePrefix), f.GoImportPath)
genFile := plugin.NewGeneratedFile(FileName(f.GeneratedFilenamePrefix), f.GoImportPath)

packageName := string(f.Desc.Package().Name())
if packageName == "" {
Expand All @@ -91,25 +115,39 @@ func (g *Generator) Generate(req *pluginpb.CodeGeneratorRequest) (res *pluginpb.

numMethods := 0
for i := 0; i < numServices; i++ {
numMethods += f.Desc.Services().Get(i).Methods().Len()
nM := f.Desc.Services().Get(i).Methods().Len()
numMethods += nM
}

err = templ.ExecuteTemplate(genFile, "base.templ", map[string]interface{}{
err = templ.ExecuteTemplate(genFile, "prebase.templ", map[string]interface{}{
"pluginVersion": version.Version,
"sourcePath": f.Desc.Path(),
"package": packageName,
"requiredImports": requiredImports,
"serviceImports": serviceImports,
"methodImports": methodImports,
"enums": f.Desc.Enums(),
"messages": f.Desc.Messages(),
"services": f.Desc.Services(),
"numServices": numServices,
"numMethods": numMethods,
})
if err != nil {
return nil, err
}

err = gen.ExecuteTemplate(genFile, f, packageName, false)
if err != nil {
return nil, err
}

err = templ.ExecuteTemplate(genFile, "base.templ", map[string]interface{}{
"enums": f.Desc.Enums(),
"messages": f.Desc.Messages(),
"services": f.Desc.Services(),
"numServices": numServices,
"numMethods": numMethods,
})
if err != nil {
return nil, err
}
}

return plugin.Response(), nil
Expand Down
Loading

0 comments on commit 331929e

Please sign in to comment.