mirror of
https://github.com/eosswedenorg/antelope-api-healthcheck
synced 2026-07-03 11:53:43 +02:00
Refactor: move internal package from src/ to internal/ and move src/main.go to cmd/eosio-api-healthcheck/main.go
This commit is contained in:
parent
c27abb5ed9
commit
6448aeb0f7
22 changed files with 19 additions and 17 deletions
4
Makefile
4
Makefile
|
|
@ -11,14 +11,12 @@ GOBUILDFLAGS = -v -ldflags='-v -s -w -X main.VersionString=$(PROGRAM_VERSION)'
|
||||||
DPKG_BUILDPACKAGE = dpkg-buildpackage
|
DPKG_BUILDPACKAGE = dpkg-buildpackage
|
||||||
DPKG_BUILDPACKAGE_FLAGS = -b -uc
|
DPKG_BUILDPACKAGE_FLAGS = -b -uc
|
||||||
|
|
||||||
SOURCES=src/main.go src/server.go src/parse_request.go
|
|
||||||
|
|
||||||
.PHONY: all build/$(PROGRAM_NAME) clean package_debian
|
.PHONY: all build/$(PROGRAM_NAME) clean package_debian
|
||||||
all: build
|
all: build
|
||||||
build: build/$(PROGRAM_NAME)
|
build: build/$(PROGRAM_NAME)
|
||||||
|
|
||||||
build/$(PROGRAM_NAME) : $(SOURCES)
|
build/$(PROGRAM_NAME) : $(SOURCES)
|
||||||
$(GO) build -o $@ $(GOBUILDFLAGS) $^
|
$(GO) build -o $@ $(GOBUILDFLAGS) cmd/eosio-api-healtcheck/main.go
|
||||||
|
|
||||||
test:
|
test:
|
||||||
$(GO) test -v ./...
|
$(GO) test -v ./...
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,8 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"syscall"
|
"syscall"
|
||||||
"github.com/eosswedenorg/eosio-api-healthcheck/src/utils"
|
"github.com/eosswedenorg/eosio-api-healthcheck/internal"
|
||||||
|
"github.com/eosswedenorg/eosio-api-healthcheck/internal/utils"
|
||||||
log "github.com/inconshreveable/log15"
|
log "github.com/inconshreveable/log15"
|
||||||
"github.com/eosswedenorg-go/pid"
|
"github.com/eosswedenorg-go/pid"
|
||||||
"github.com/pborman/getopt/v2"
|
"github.com/pborman/getopt/v2"
|
||||||
|
|
@ -127,7 +128,7 @@ func main() {
|
||||||
var addr string
|
var addr string
|
||||||
var logFormatter *string
|
var logFormatter *string
|
||||||
|
|
||||||
logger = log.New()
|
logger = log.Root()
|
||||||
|
|
||||||
// Command line parsing
|
// Command line parsing
|
||||||
getopt.SetParameters("[ip] [port]")
|
getopt.SetParameters("[ip] [port]")
|
||||||
|
|
@ -171,7 +172,7 @@ func main() {
|
||||||
addr = argv_listen_addr()
|
addr = argv_listen_addr()
|
||||||
|
|
||||||
// Start listening to TCP Connections
|
// Start listening to TCP Connections
|
||||||
err := spawnTcpServer(addr)
|
err := internal.SpawnTcpServer(addr)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
logger.Info("TCP Server started", "addr", addr)
|
logger.Info("TCP Server started", "addr", addr)
|
||||||
|
|
||||||
|
|
@ -3,7 +3,7 @@ package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/eosswedenorg/eosio-api-healthcheck/src/utils"
|
"github.com/eosswedenorg/eosio-api-healthcheck/internal/utils"
|
||||||
"github.com/eosswedenorg-go/haproxy/agentcheck"
|
"github.com/eosswedenorg-go/haproxy/agentcheck"
|
||||||
contract_api "github.com/eosswedenorg-go/eos-contract-api-client"
|
contract_api "github.com/eosswedenorg-go/eos-contract-api-client"
|
||||||
)
|
)
|
||||||
|
|
@ -3,7 +3,7 @@ package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/eosswedenorg/eosio-api-healthcheck/src/utils"
|
"github.com/eosswedenorg/eosio-api-healthcheck/internal/utils"
|
||||||
"github.com/eosswedenorg-go/haproxy/agentcheck"
|
"github.com/eosswedenorg-go/haproxy/agentcheck"
|
||||||
"github.com/eosswedenorg-go/eosapi"
|
"github.com/eosswedenorg-go/eosapi"
|
||||||
)
|
)
|
||||||
|
|
@ -3,7 +3,7 @@ package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/eosswedenorg/eosio-api-healthcheck/src/utils"
|
"github.com/eosswedenorg/eosio-api-healthcheck/internal/utils"
|
||||||
"github.com/eosswedenorg-go/haproxy/agentcheck"
|
"github.com/eosswedenorg-go/haproxy/agentcheck"
|
||||||
"github.com/eosswedenorg-go/eosapi"
|
"github.com/eosswedenorg-go/eosapi"
|
||||||
)
|
)
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
|
|
||||||
package main
|
package internal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
"github.com/eosswedenorg/eosio-api-healthcheck/src/api"
|
"github.com/eosswedenorg/eosio-api-healthcheck/internal/api"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ParseArguments(args []string) api.ApiArguments {
|
func ParseArguments(args []string) api.ApiArguments {
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
|
|
||||||
package main
|
package internal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
// "fmt"
|
// "fmt"
|
||||||
"testing"
|
"testing"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/eosswedenorg/eosio-api-healthcheck/src/api"
|
"github.com/eosswedenorg/eosio-api-healthcheck/internal/api"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestParseWithInvalidApi(t *testing.T) {
|
func TestParseWithInvalidApi(t *testing.T) {
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
package main
|
package internal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
||||||
"github.com/eosswedenorg/eosio-api-healthcheck/src/api"
|
log "github.com/inconshreveable/log15"
|
||||||
|
"github.com/eosswedenorg/eosio-api-healthcheck/internal/api"
|
||||||
"github.com/eosswedenorg-go/haproxy/agentcheck"
|
"github.com/eosswedenorg-go/haproxy/agentcheck"
|
||||||
"github.com/eosswedenorg-go/tcp_server"
|
"github.com/eosswedenorg-go/tcp_server"
|
||||||
)
|
)
|
||||||
|
|
@ -12,6 +13,8 @@ import (
|
||||||
|
|
||||||
func onTcpMessage(c *tcp_server.Client, args string) {
|
func onTcpMessage(c *tcp_server.Client, args string) {
|
||||||
|
|
||||||
|
logger := log.Root()
|
||||||
|
|
||||||
// Check api.
|
// Check api.
|
||||||
// -------------------
|
// -------------------
|
||||||
healthCheckApi, err := ParseRequest(args)
|
healthCheckApi, err := ParseRequest(args)
|
||||||
|
|
@ -39,10 +42,10 @@ func onTcpMessage(c *tcp_server.Client, args string) {
|
||||||
c.Close()
|
c.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
// spawnTcpServer
|
// SpawnTcpServer
|
||||||
// ---------------------------------------------------------
|
// ---------------------------------------------------------
|
||||||
|
|
||||||
func spawnTcpServer(addr string) error {
|
func SpawnTcpServer(addr string) error {
|
||||||
server := tcp_server.New(addr)
|
server := tcp_server.New(addr)
|
||||||
server.OnMessage(onTcpMessage)
|
server.OnMessage(onTcpMessage)
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue