Skip to content
Permalink
Browse files
Add supported structure
  • Loading branch information
spacewander committed May 18, 2021
1 parent d0e3a4e commit b4b6bc004b38863ec72c94ebc22edc12aad25b3e
Showing 7 changed files with 462 additions and 2 deletions.
@@ -0,0 +1,7 @@
go-runner
!go-runner/
release/
*.tgz
.idea
.DS_Store
coverage.txt
@@ -0,0 +1,19 @@
run:
skip-files:
- ".*_test.go$"

linters:
disable-all: true
enable:
- deadcode
- errcheck
- goimports
- gosimple
- ineffassign
- misspell
- staticcheck
- structcheck
- unconvert
- unused
- varcheck
- vet
@@ -0,0 +1,74 @@
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
default: help

VERSION ?= latest
RELEASE_SRC = apache-apisix-go-plugin-runner-${VERSION}-src

GITSHA ?= $(shell git rev-parse --short=7 HEAD)
OSNAME ?= $(shell uname -s | tr A-Z a-z)
OSARCH ?= $(shell uname -m | tr A-Z a-z)
PWD ?= $(shell pwd)
ifeq ($(OSARCH), x86_64)
OSARCH = amd64
endif

VERSYM=main._buildVersion
GITSHASYM=main._buildGitRevision
BUILDOSSYM=main._buildOS
GO_LDFLAGS ?= "-X '$(VERSYM)=$(VERSION)' -X '$(GITSHASYM)=$(GITSHA)' -X '$(BUILDOSSYM)=$(OSNAME)/$(OSARCH)'"

.PHONY: build
build:
cd cmd/go-runner && \
go build -ldflags $(GO_LDFLAGS) && \
mv go-runner ../..

.PHONY: lint
lint:
golangci-lint run --verbose

.PHONY: test
test:
go test -race -cover -coverprofile=coverage.txt ./...

.PHONY: release-src
release-src: compress-tar
gpg --batch --yes --armor --detach-sig $(RELEASE_SRC).tgz
shasum -a 512 $(RELEASE_SRC).tgz > $(RELEASE_SRC).tgz.sha512

mkdir -p release
mv $(RELEASE_SRC).tgz release/$(RELEASE_SRC).tgz
mv $(RELEASE_SRC).tgz.asc release/$(RELEASE_SRC).tgz.asc
mv $(RELEASE_SRC).tgz.sha512 release/$(RELEASE_SRC).tgz.sha512

.PHONY: compress-tar
compress-tar:
tar -zcvf $(RELEASE_SRC).tgz \
./cmd \
./internal \
LICENSE \
Makefile \
go.mod \
go.sum \
*.md

.PHONY: help
help:
@echo Makefile rules:
@echo
@grep -E '^### [-A-Za-z0-9_]+:' Makefile | sed 's/###/ /'
@@ -14,8 +14,60 @@
// limitations under the License.
package main

import "github.com/apache/apisix-go-plugin-runner/internal/server"
import (
"fmt"
"os"

"github.com/spf13/cobra"

"github.com/apache/apisix-go-plugin-runner/internal/server"
)

func newVersionCommand() *cobra.Command {
var long bool
cmd := &cobra.Command{
Use: "version",
Short: "version",
Run: func(cmd *cobra.Command, _ []string) {
if long {
fmt.Print(longVersion())
} else {
fmt.Printf("version %s\n", shortVersion())
}
},
}

cmd.PersistentFlags().BoolVar(&long, "long", false, "show long mode version information")
return cmd
}

func newRunCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "run",
Short: "run",
Run: func(cmd *cobra.Command, _ []string) {
server.Run()
},
}
return cmd
}

func NewCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "apisix-go-plugin-runner [command]",
Long: "The Plugin runner to run Go plugins",
Version: shortVersion(),
}

cmd.AddCommand(newRunCommand())
cmd.AddCommand(newVersionCommand())
return cmd
}

func main() {
server.Run()
root := NewCommand()
if err := root.Execute(); err != nil {
fmt.Fprintln(os.Stderr, err.Error())
os.Exit(1)
}
}
@@ -0,0 +1,53 @@
// Licensed to the Apache Software Foundation (ASF) under one or more
// contributor license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright ownership.
// The ASF licenses this file to You under the Apache License, Version 2.0
// (the "License"); you may not use this file except in compliance with
// the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package main

import (
"bytes"
"fmt"
"runtime"
)

var (
// The following fields are populated at build time using -ldflags -X.
_buildVersion = "unknown"
_buildGitRevision = "unknown"
_buildOS = "unknown"

_buildGoVersion = runtime.Version()
_runningOS = runtime.GOOS + "/" + runtime.GOARCH
)

// shortVersion produces a single-line version info with format:
// <version>-<git revision>-<go version>
func shortVersion() string {
return fmt.Sprintf("%s-%s-%s", _buildVersion, _buildGitRevision, _buildGoVersion)
}

// longVersion produces a verbose version info with format:
// Version: xxx
// Git SHA: xxx
// GO Version: xxx
// Running OS/Arch: xxx/xxx
// Building OS/Arch: xxx/xxx
func longVersion() string {
buf := bytes.NewBuffer(nil)
fmt.Fprintln(buf, "Version:", _buildVersion)
fmt.Fprintln(buf, "Git SHA:", _buildGitRevision)
fmt.Fprintln(buf, "Go Version:", _buildGoVersion)
fmt.Fprintln(buf, "Building OS/Arch:", _buildOS)
fmt.Fprintln(buf, "Running OS/Arch:", _runningOS)
return buf.String()
}
1 go.mod
@@ -3,6 +3,7 @@ module github.com/apache/apisix-go-plugin-runner
go 1.15

require (
github.com/spf13/cobra v1.1.3
github.com/stretchr/testify v1.7.0
go.uber.org/multierr v1.7.0 // indirect
go.uber.org/zap v1.16.0

0 comments on commit b4b6bc0

Please sign in to comment.