-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#7]: feat(API): API unification, move all SDK interfaces to the API
- Loading branch information
Showing
27 changed files
with
737 additions
and
251 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
name: Linux | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
- beta | ||
- stable | ||
tags-ignore: | ||
- "**" | ||
paths-ignore: | ||
- "**.md" | ||
- "**.yaml" | ||
- "**.yml" | ||
pull_request: | ||
paths-ignore: | ||
- "**.md" | ||
- "**.yaml" | ||
- "**.yml" | ||
|
||
jobs: | ||
golang: | ||
name: Build (Go ${{ matrix.go }}, OS ${{matrix.os}}) | ||
runs-on: ${{ matrix.os }} | ||
timeout-minutes: 60 | ||
strategy: | ||
fail-fast: true | ||
matrix: | ||
go: ["1.17.7"] | ||
os: ["ubuntu-latest"] | ||
steps: | ||
- name: Set up Go ${{ matrix.go }} | ||
uses: actions/setup-go@v2 # action page: <https://github.com/actions/setup-go> | ||
with: | ||
go-version: ${{ matrix.go }} | ||
|
||
- name: Check out code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Init Go modules Cache # Docs: <https://git.io/JfAKn#go---modules> | ||
uses: actions/cache@v2 | ||
with: | ||
path: ~/go/pkg/mod | ||
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} | ||
restore-keys: ${{ runner.os }}-go- | ||
|
||
- name: Install Go dependencies | ||
run: go mod download | ||
|
||
- name: Run golang tests with coverage | ||
run: make test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package bst | ||
|
||
// Storage is general in-memory BST storage implementation | ||
type Storage interface { | ||
// Insert inserts to a vertex with topic ident connection uuid | ||
Insert(uuid string, topic string) | ||
// Remove removes uuid from topic, if the uuid is single for a topic, whole vertex will be removed | ||
Remove(uuid, topic string) | ||
// Get will return all connections associated with the topic | ||
Get(topic string) map[string]struct{} | ||
// Contains checks if the BST contains a topic | ||
Contains(topic string) bool | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package event_bus //nolint:stylecheck | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
type EventBus interface { | ||
SubscribeAll(subID string, ch chan<- Event) error | ||
SubscribeP(subID string, pattern string, ch chan<- Event) error | ||
Unsubscribe(subID string) | ||
UnsubscribeP(subID, pattern string) | ||
Len() uint | ||
Send(ev Event) | ||
} | ||
|
||
type Event interface { | ||
Type() fmt.Stringer | ||
Plugin() string | ||
Message() string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
//go:build race | ||
|
||
package internal | ||
|
||
import ( | ||
"crypto/sha512" | ||
"fmt" | ||
"runtime" | ||
) | ||
|
||
func SetChecker(b []byte) { | ||
if len(b) == 0 { | ||
return | ||
} | ||
c := checkIfConst(b) | ||
go c.isStillConst() | ||
runtime.SetFinalizer(c, (*constSlice).isStillConst) | ||
} | ||
|
||
type constSlice struct { | ||
b []byte | ||
checksum [64]byte | ||
} | ||
|
||
func checkIfConst(b []byte) *constSlice { | ||
c := &constSlice{b: b} | ||
c.checksum = sha512.Sum512(c.b) | ||
return c | ||
} | ||
|
||
func (c *constSlice) isStillConst() { | ||
if sha512.Sum512(c.b) != c.checksum { | ||
panic(fmt.Sprintf("mutable access detected 0x%012x", &c.b[0])) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
//go:build !race | ||
|
||
package internal | ||
|
||
func SetChecker(_ []byte) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package internal | ||
|
||
import ( | ||
"reflect" | ||
"unsafe" | ||
) | ||
|
||
// AsBytes returns a slice that refers to the data backing the string s. | ||
func AsBytes(s string) []byte { | ||
// get the pointer to the data of the string | ||
p := unsafe.Pointer((*reflect.StringHeader)(unsafe.Pointer(&s)).Data) | ||
|
||
var b []byte | ||
hdr := (*reflect.SliceHeader)(unsafe.Pointer(&b)) | ||
hdr.Data = uintptr(p) | ||
// we need to set the cap and len for the string to byte convert | ||
// because string is shorter than []bytes | ||
hdr.Cap = len(s) | ||
hdr.Len = len(s) | ||
|
||
// checker to check mutable access to the data | ||
SetChecker(b) | ||
return b | ||
} | ||
|
||
// AsString returns a string that refers to the data backing the slice s. | ||
func AsString(b []byte) string { | ||
p := unsafe.Pointer((*reflect.SliceHeader)(unsafe.Pointer(&b)).Data) | ||
|
||
var s string | ||
hdr := (*reflect.StringHeader)(unsafe.Pointer(&s)) | ||
hdr.Data = uintptr(p) | ||
hdr.Len = len(b) | ||
|
||
// checker to check mutable access to the data | ||
SetChecker(b) | ||
return s | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package ipc | ||
|
||
import ( | ||
"context" | ||
"os/exec" | ||
|
||
"github.com/roadrunner-server/api/v2/worker" | ||
) | ||
|
||
// Factory is responsible for wrapping given command into tasks WorkerProcess. | ||
type Factory interface { | ||
// SpawnWorkerWithTimeout creates new WorkerProcess process based on given command with context. | ||
// Process must not be started. | ||
SpawnWorkerWithTimeout(context.Context, *exec.Cmd) (worker.BaseProcess, error) | ||
// SpawnWorker creates new WorkerProcess process based on given command. | ||
// Process must not be started. | ||
SpawnWorker(*exec.Cmd) (worker.BaseProcess, error) | ||
// Close the factory and underlying connections. | ||
Close() error | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package payload | ||
|
||
import ( | ||
"github.com/roadrunner-server/api/v2/internal" | ||
) | ||
|
||
// Payload carries binary header and body to stack and | ||
// back to the server. | ||
type Payload struct { | ||
// Context represent payload context, might be omitted. | ||
Context []byte | ||
|
||
// body contains binary payload to be processed by WorkerProcess. | ||
Body []byte | ||
|
||
// Type of codec used to decode/encode payload | ||
Codec byte | ||
} | ||
|
||
// String returns payload body as string | ||
func (p *Payload) String() string { | ||
return internal.AsString(p.Body) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.