mirror of
https://github.com/jwetzell/showbridge-go.git
synced 2026-04-27 05:15:47 +00:00
Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
38857f7a29 | ||
|
|
45965a4eac | ||
|
|
b372b53422 | ||
|
|
97cf721abc | ||
|
|
afa32b8c2f | ||
|
|
d3244fbe90 | ||
|
|
d6e73d1bb0 | ||
|
|
067412ec9f | ||
|
|
0741cd2293 |
11
.github/labeler.yml
vendored
Normal file
11
.github/labeler.yml
vendored
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
framing:
|
||||||
|
- changed-files:
|
||||||
|
- any-glob-to-any-file: 'internal/framing/**'
|
||||||
|
|
||||||
|
processing:
|
||||||
|
- changed-files:
|
||||||
|
- any-glob-to-any-file: 'internal/processing/**'
|
||||||
|
|
||||||
|
cli:
|
||||||
|
- changed-files:
|
||||||
|
- any-glob-to-any-file: 'cmd/showbridge/**'
|
||||||
19
.github/release.yml
vendored
Normal file
19
.github/release.yml
vendored
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
changelog:
|
||||||
|
exclude:
|
||||||
|
authors:
|
||||||
|
- dependabot
|
||||||
|
labels:
|
||||||
|
- dependencies
|
||||||
|
categories:
|
||||||
|
- title: Framing 🖼️
|
||||||
|
labels:
|
||||||
|
- framing
|
||||||
|
- title: Processing 🏭
|
||||||
|
labels:
|
||||||
|
- processing
|
||||||
|
- title: CLI ⌨️
|
||||||
|
labels:
|
||||||
|
- cmd
|
||||||
|
- title: Other Changes
|
||||||
|
labels:
|
||||||
|
- '*'
|
||||||
18
.github/workflows/label-pr.yaml
vendored
Normal file
18
.github/workflows/label-pr.yaml
vendored
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
# Taken from https://github.com/go-gitea/gitea
|
||||||
|
name: Add labels to PR
|
||||||
|
on:
|
||||||
|
pull_request_target:
|
||||||
|
types: [opened, synchronize, reopened]
|
||||||
|
concurrency:
|
||||||
|
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
|
||||||
|
cancel-in-progress: true
|
||||||
|
jobs:
|
||||||
|
labeler:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
pull-requests: write
|
||||||
|
steps:
|
||||||
|
- uses: actions/labeler@634933edcd8ababfe52f92936142cc22ac488b1b # v6.0.1
|
||||||
|
with:
|
||||||
|
sync-labels: true
|
||||||
@@ -24,6 +24,7 @@ archives:
|
|||||||
|
|
||||||
changelog:
|
changelog:
|
||||||
sort: asc
|
sort: asc
|
||||||
|
use: github-native
|
||||||
|
|
||||||
release:
|
release:
|
||||||
draft: true
|
draft: true
|
||||||
|
|||||||
39
internal/processing/float-parse.go
Normal file
39
internal/processing/float-parse.go
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
package processing
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"strconv"
|
||||||
|
)
|
||||||
|
|
||||||
|
type FloatParse struct {
|
||||||
|
config ProcessorConfig
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fp *FloatParse) Process(ctx context.Context, payload any) (any, error) {
|
||||||
|
payloadString, ok := payload.(string)
|
||||||
|
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("float.parse processor only accepts a string")
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO(jwetzell): make bitSize configurable
|
||||||
|
payloadFloat, err := strconv.ParseFloat(payloadString, 64)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return payloadFloat, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fp *FloatParse) Type() string {
|
||||||
|
return fp.config.Type
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
RegisterProcessor(ProcessorRegistration{
|
||||||
|
Type: "float.parse",
|
||||||
|
New: func(config ProcessorConfig) (Processor, error) {
|
||||||
|
return &FloatParse{config: config}, nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
39
internal/processing/int-parse.go
Normal file
39
internal/processing/int-parse.go
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
package processing
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"strconv"
|
||||||
|
)
|
||||||
|
|
||||||
|
type IntParse struct {
|
||||||
|
config ProcessorConfig
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ip *IntParse) Process(ctx context.Context, payload any) (any, error) {
|
||||||
|
payloadString, ok := payload.(string)
|
||||||
|
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("int.parse processor only accepts a string")
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO(jwetzell): make base and bitSize configurable
|
||||||
|
payloadInt, err := strconv.ParseInt(payloadString, 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return payloadInt, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ip *IntParse) Type() string {
|
||||||
|
return ip.config.Type
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
RegisterProcessor(ProcessorRegistration{
|
||||||
|
Type: "int.parse",
|
||||||
|
New: func(config ProcessorConfig) (Processor, error) {
|
||||||
|
return &IntParse{config: config}, nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -31,6 +31,10 @@ func (sj *ScriptJS) Process(ctx context.Context, payload any) (any, error) {
|
|||||||
|
|
||||||
_, err = vm.Eval(sj.Program, quickjs.EvalGlobal)
|
_, err = vm.Eval(sj.Program, quickjs.EvalGlobal)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
output, err := vm.GetProperty(vm.GlobalObject(), payloadAtom)
|
output, err := vm.GetProperty(vm.GlobalObject(), payloadAtom)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
57
internal/processing/string-create.go
Normal file
57
internal/processing/string-create.go
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
package processing
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"text/template"
|
||||||
|
)
|
||||||
|
|
||||||
|
type StringCreate struct {
|
||||||
|
config ProcessorConfig
|
||||||
|
Template *template.Template
|
||||||
|
}
|
||||||
|
|
||||||
|
func (sc *StringCreate) Process(ctx context.Context, payload any) (any, error) {
|
||||||
|
var templateBuffer bytes.Buffer
|
||||||
|
err := sc.Template.Execute(&templateBuffer, payload)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
payloadString := templateBuffer.String()
|
||||||
|
|
||||||
|
return payloadString, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (sc *StringCreate) Type() string {
|
||||||
|
return sc.config.Type
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
RegisterProcessor(ProcessorRegistration{
|
||||||
|
Type: "string.create",
|
||||||
|
New: func(config ProcessorConfig) (Processor, error) {
|
||||||
|
params := config.Params
|
||||||
|
tmpl, ok := params["template"]
|
||||||
|
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("string.create requires a template parameter")
|
||||||
|
}
|
||||||
|
|
||||||
|
templateString, ok := tmpl.(string)
|
||||||
|
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("string.create template must be a string")
|
||||||
|
}
|
||||||
|
|
||||||
|
templateTemplate, err := template.New("template").Parse(templateString)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &StringCreate{config: config, Template: templateTemplate}, nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
39
internal/processing/uint-parse.go
Normal file
39
internal/processing/uint-parse.go
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
package processing
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"strconv"
|
||||||
|
)
|
||||||
|
|
||||||
|
type UintParse struct {
|
||||||
|
config ProcessorConfig
|
||||||
|
}
|
||||||
|
|
||||||
|
func (up *UintParse) Process(ctx context.Context, payload any) (any, error) {
|
||||||
|
payloadString, ok := payload.(string)
|
||||||
|
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("uint.parse processor only accepts a string")
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO(jwetzell): make base and bitSize configurable
|
||||||
|
payloadUint, err := strconv.ParseUint(payloadString, 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return payloadUint, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (up *UintParse) Type() string {
|
||||||
|
return up.config.Type
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
RegisterProcessor(ProcessorRegistration{
|
||||||
|
Type: "uint.parse",
|
||||||
|
New: func(config ProcessorConfig) (Processor, error) {
|
||||||
|
return &UintParse{config: config}, nil
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user