API blueprint parser for Go. It's a Go bindings for the Drafter library.
This library can be consumed using two ways:
- RPC-based plugin (recommended)
- Go plugin
RPC-based plugin is based on Hashicorp's go-plugin.
- Download file drafter-rpc-* from releases page
- Rename it as
drafter-rpc
- Add executable permission (chmod +x drafter.so)
- Place it in the registered PATH directory
- Run this file:
go run ./main.go
package main
import (
"fmt"
"log"
"os"
"strings"
"github.com/bukalapak/drafter-go"
rc "github.com/bukalapak/drafter-go/rpc-plugin/client"
)
func main() {
client := rc.New(rc.Config{})
defer client.Close()
engine, err := client.Dispense()
if err != nil {
log.Fatalln(err)
os.Exit(1)
}
input := strings.NewReader("# API")
options := drafter.Options{
Format: drafter.JSON,
}
b, _ := engine.Parse(input, options)
fmt.Printf("OUTPUT: %s\n", b)
}
To consume this library as go plugin. You need to:
- Download file *.so from releases page
- Rename it as
drafter.so
- Place it in the same directory with this file
- Note: due to the go plugin limitation, we need to mimics GitHub build environment:
export WORKDIR=/home/runner/work/drafter-go mkdir -p $WORKDIR git clone https://github.com/bukalapak/drafter-go.git $WORKDIR/drafter-go echo "replace github.com/bukalapak/drafter-go => $WORKDIR/drafter-go" >> go.mod
- Run this file:
go run ./main.go
package main
import (
"fmt"
"log"
"os"
"strings"
"github.com/bukalapak/drafter-go"
rc "github.com/bukalapak/drafter-go/plugin/client"
)
func main() {
engine, err := rc.New(rc.Config{})
if err != nil {
log.Fatalf("Error: %s\n", err)
os.Exit(1)
}
input := strings.NewReader("# API")
options := drafter.Options{
Format: drafter.JSON,
}
b, _ := engine.Parse(input, options)
fmt.Printf("OUTPUT: %s\n", b)
}