Skip to content

Commit

Permalink
feat(init): init repo
Browse files Browse the repository at this point in the history
  • Loading branch information
Vincenzo authored and Vincenzo committed Aug 31, 2024
0 parents commit 20b313a
Show file tree
Hide file tree
Showing 24 changed files with 1,438 additions and 0 deletions.
63 changes: 63 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
*.o
*.a
*.so
*.test
*.prof

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
# vendor/

# Folders
_obj
_test
kafka

# Architecture specific extensions/prefixes
*.[568vq]
[568vq].out

*.cgo1.go
*.cgo2.c
_cgo_defun.c
_cgo_gotypes.go
_cgo_export.*
_testmain.go

# Various
*~
*.iws
*.ipr
*.iml
.idea/
.idea
.DS_Store

# Specific project files
releases
build
pkg/types/*.go
pkg/producers/kafka/*.properties
pkg/producers/redis/config.json
pkg/producers/elastic/*.json
pkg/producers/mongoDB/*.json
pkg/producers/gcs/*.json
pkg/producers/s3/*.json

# python virtual environment
.venv
__pycache__

# vscode
.vscode
37 changes: 37 additions & 0 deletions .localci/lint/golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
run:
# The default concurrency value is the number of available CPU.
# concurrency: 2
tests: true
timeout: 20m
allow-parallel-runners: true
go: 1.23

linters:
enable:
- errcheck
- typecheck
- asciicheck
- bidichk
- bodyclose
- dupl
- gocritic
#- gofmt
- gosimple
- gosec
- govet
- goconst
- ineffassign
- nakedret
- revive
- staticcheck
- unused
fast: false

linters-settings:
dupl:
threshold: 400

#output:
# formats:
# - format: html
# path: golangci.html
23 changes: 23 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: trailing-whitespace
args: [--markdown-linebreak-ext=md]
- id: end-of-file-fixer
- id: fix-byte-order-marker
- id: mixed-line-ending
- id: check-merge-conflict
- id: check-case-conflict
- id: check-docstring-first
- repo: https://github.com/Lucas-C/pre-commit-hooks
rev: v1.3.1
hooks:
- id: remove-crlf
- repo: https://github.com/golangci/golangci-lint
rev: v1.60.3
hooks:
- id: golangci-lint
args:
- --config
- .localci/lint/golangci.yml
103 changes: 103 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
VERSION=2.0.0
GOVERSION=$(shell go version)
USER=$(shell id -u -n)
TIME=$(shell date)
JR_HOME=jr

ifndef XDG_DATA_DIRS
ifeq ($(OS), Windows_NT)
detectedOS := Windows
else
detectedOS := $(shell sh -c 'uname 2>/dev/null || echo Unknown')
endif

ifeq ($(detectedOS), Darwin)
JR_SYSTEM_DIR="$(HOME)/Library/Application Support"
endif
ifeq ($(detectedOS), Linux)
JR_SYSTEM_DIR="$(HOME)/.config"
endif
ifeq ($(detectedOS), Windows_NT)
JR_SYSTEM_DIR="$(LOCALAPPDATA)"
endif
else
JR_SYSTEM_DIR=$(XDG_DATA_DIRS)
endif

ifndef XDG_DATA_HOME
ifeq ($(OS), Windows_NT)
detectedOS := Windows
else
detectedOS := $(shell sh -c 'uname 2>/dev/null || echo Unknown')
endif

ifeq ($(detectedOS), Darwin)
JR_USER_DIR="$(HOME)/.local/share"
endif
ifeq ($(detectedOS), Linux)
JR_USER_DIR="$(HOME)/.local/share"
endif
ifeq ($(detectedOS), Windows_NT)
JR_USER_DIR="$(LOCALAPPDATA)" //@TODO
endif
else
JR_USER_DIR=$(XDG_DATA_HOME)
endif

PLUGINS=mongodb \
azblobstorage \
luascript

hello:
@echo "JR Plugins"
@echo " Version: $(VERSION)"
@echo " Go Version: $(GOVERSION)"
@echo " Build User: $(USER)"
@echo " Build Time: $(TIME)"
@echo " Detected OS: $(detectedOS)"
@echo " JR System Dir: $(JR_SYSTEM_DIR)"
@echo " JR User Dir: $(JR_USER_DIR)"


compile: hello lint test
@echo "Compiling"
for plugin in $(PLUGINS); do \
echo "building plugin jr-$$plugin"; \
go build -v -ldflags="-X 'main.Version=$(VERSION)' \
-X 'main.GoVersion=$(GOVERSION)' \
-X 'main.BuildUser=$(USER)' \
-X 'main.BuildTime=$(TIME)'" \
-tags $$plugin \
-o build/jr-$$plugin github.com/jrnd-io/jr-plugins/cmd/plugin; \
done


clean:
go clean
rm build/*

test:
go clean -testcache
go test ./...

test_coverage:
go test ./... -coverprofile=coverage.out

dep:
go mod download

vet:
go vet

lint:
golangci-lint run --config .localci/lint/golangci.yml

help: hello
@echo ''
@echo 'Usage:'
@echo ' ${YELLOW}make${RESET} ${GREEN}all${RESET}'
@echo ''


all: hello compile
all_offline: hello compile
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# JR Plugins
32 changes: 32 additions & 0 deletions cmd/plugin/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright © 2024 JR team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
package main

import (
"github.com/rs/zerolog/log"
)

func main() {

if err := rootCmd.Execute(); err != nil {
log.Fatal().Err(err).Msg("error executing root command")
}

}
30 changes: 30 additions & 0 deletions cmd/plugin/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright © 2024 JR team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
package main

import (
"github.com/spf13/cobra"
)

var rootCmd = &cobra.Command{
Use: "jrplugin",
Short: "jrplugin, a plugin for jr",
Long: "jrplugin is a plugin system for jr",
}
93 changes: 93 additions & 0 deletions cmd/plugin/run.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
// Copyright © 2024 JR team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
package main

import (
"context"
"os"

"github.com/rs/zerolog/log"
"github.com/spf13/cobra"

hashiplugin "github.com/hashicorp/go-plugin"
"github.com/jrnd-io/jr-plugins/internal/plugin"
_ "github.com/jrnd-io/jr-plugins/internal/plugin/azblobstorage"
_ "github.com/jrnd-io/jr-plugins/internal/plugin/luascript"
_ "github.com/jrnd-io/jr-plugins/internal/plugin/mongodb"
"github.com/jrnd-io/jrv2/pkg/jrpc"
)

var (
runCmd = &cobra.Command{
Use: "run",
Short: "Run plugin",
Long: "Run plugin",
Run: run,
}
cfgFile string
cfgBytes []byte
)

func init() {

cobra.OnInitialize(readConfig)
runCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.cobra.yaml)")
rootCmd.AddCommand(runCmd)
}

func readConfig() {
var err error
if cfgFile == "" {
log.Fatal().Msg("config file is required")
}

cfgBytes, err = os.ReadFile(cfgFile)
if err != nil {
log.Fatal().Err(err).Msg("failed to read config file")

}

}

func run(_ *cobra.Command, _ []string) {
// check registered plugin

p := plugin.GetPlugin()
if p == nil {
log.Fatal().Msg("plugin instance is null")
}

// init plugin
err := p.Init(context.Background(), cfgBytes)
if err != nil {
log.Fatal().Err(err).Msg("failed to initialize plugin")
}

hashiplugin.Serve(&hashiplugin.ServeConfig{
HandshakeConfig: jrpc.Handshake,
Plugins: map[string]hashiplugin.Plugin{
"jr-plugin": &jrpc.ProducerGRPCPlugin{Impl: p},
},

// A non-nil value here enables gRPC serving for this plugin...
GRPCServer: hashiplugin.DefaultGRPCServer,
})

}
Loading

0 comments on commit 20b313a

Please sign in to comment.