mirror of
https://github.com/xaionaro-go/streamctl.git
synced 2025-10-16 12:30:47 +08:00
Initial commit, pt. 70
This commit is contained in:
@@ -5,4 +5,4 @@ Website = "https://github.com/xaionaro/streamctl"
|
|||||||
Name = "streampanel"
|
Name = "streampanel"
|
||||||
ID = "center.dx.streampanel"
|
ID = "center.dx.streampanel"
|
||||||
Version = "0.1.0"
|
Version = "0.1.0"
|
||||||
Build = 85
|
Build = 87
|
||||||
|
@@ -29,7 +29,11 @@ func getContext(
|
|||||||
l := xlogrus.New(ll).WithLevel(logger.Level(flags.LoggerLevel))
|
l := xlogrus.New(ll).WithLevel(logger.Level(flags.LoggerLevel))
|
||||||
|
|
||||||
if flags.LogFile != "" {
|
if flags.LogFile != "" {
|
||||||
logPath, err := xpath.Expand(flags.LogFile)
|
logPathUnexpanded := flags.LogFile
|
||||||
|
if flags.Subprocess != "" {
|
||||||
|
logPathUnexpanded += "-" + flags.Subprocess
|
||||||
|
}
|
||||||
|
logPath, err := xpath.Expand(logPathUnexpanded)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
l.Errorf("unable to expand path '%s': %w", flags.LogFile, err)
|
l.Errorf("unable to expand path '%s': %w", flags.LogFile, err)
|
||||||
} else {
|
} else {
|
||||||
|
@@ -95,6 +95,14 @@ func initRuntime(
|
|||||||
runtime.GOMAXPROCS(16)
|
runtime.GOMAXPROCS(16)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
observability.Go(ctx, func() {
|
||||||
|
t := time.NewTicker(time.Second)
|
||||||
|
for {
|
||||||
|
<-t.C
|
||||||
|
belt.Flush(ctx)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
ctx, cancelFn := context.WithCancel(ctx)
|
ctx, cancelFn := context.WithCancel(ctx)
|
||||||
return ctx, func() {
|
return ctx, func() {
|
||||||
defer belt.Flush(ctx)
|
defer belt.Flush(ctx)
|
||||||
|
@@ -3,6 +3,7 @@ package observability
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/facebookincubator/go-belt"
|
"github.com/facebookincubator/go-belt"
|
||||||
"github.com/facebookincubator/go-belt/tool/experimental/errmon"
|
"github.com/facebookincubator/go-belt/tool/experimental/errmon"
|
||||||
@@ -14,5 +15,6 @@ func PanicIfNotNil(ctx context.Context, r any) {
|
|||||||
}
|
}
|
||||||
errmon.ObserveRecoverCtx(ctx, r)
|
errmon.ObserveRecoverCtx(ctx, r)
|
||||||
belt.Flush(ctx)
|
belt.Flush(ctx)
|
||||||
|
time.Sleep(time.Second)
|
||||||
panic(fmt.Sprintf("%#+v", r))
|
panic(fmt.Sprintf("%#+v", r))
|
||||||
}
|
}
|
||||||
|
@@ -2,12 +2,13 @@ package config
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
goyaml "github.com/go-yaml/yaml"
|
|
||||||
"github.com/goccy/go-yaml"
|
"github.com/goccy/go-yaml"
|
||||||
"github.com/xaionaro-go/datacounter"
|
"github.com/xaionaro-go/datacounter"
|
||||||
|
goyaml "gopkg.in/yaml.v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ io.Writer = (*Config)(nil)
|
var _ io.Writer = (*Config)(nil)
|
||||||
@@ -33,22 +34,31 @@ func (cfg Config) WriteTo(
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (cfg Config) MarshalYAML() ([]byte, error) {
|
func (cfg Config) MarshalYAML() ([]byte, error) {
|
||||||
b, err := yaml.Marshal((config)(cfg))
|
var buf bytes.Buffer
|
||||||
|
// There is bug in github.com/goccy/go-yaml that makes wrong intention
|
||||||
|
// in cfg.BuiltinStreamD.GitRepo.PrivateKey makes the whole value unparsable
|
||||||
|
//
|
||||||
|
// Working this around...
|
||||||
|
opt := yaml.CustomMarshaler(func(v string) ([]byte, error) {
|
||||||
|
fmt.Println(v)
|
||||||
|
return json.Marshal(v)
|
||||||
|
})
|
||||||
|
encoder := yaml.NewEncoder(&buf, opt)
|
||||||
|
err := encoder.Encode((config)(cfg))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("unable to serialize data %#+v: %w", cfg, err)
|
return nil, fmt.Errorf("unable to serialize data %#+v: %w", cfg, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// have to use another YAML encoder to avoid the random-indent bug,
|
// have to use another YAML encoder to avoid the random-indent bug,
|
||||||
// but also have to use the initial encoder to correctly map
|
// but also have to use the initial encoder to correctly map
|
||||||
// out structures to YAML; so using both sequentially :(
|
// out structures to YAML; so using both sequentially :(
|
||||||
|
|
||||||
m := map[string]any{}
|
m := map[string]any{}
|
||||||
err = goyaml.Unmarshal(b, &m)
|
err = goyaml.Unmarshal(buf.Bytes(), &m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("unable to unserialize data %s: %w", b, err)
|
return nil, fmt.Errorf("unable to unserialize data %s: %w", buf.Bytes(), err)
|
||||||
}
|
}
|
||||||
|
|
||||||
b, err = goyaml.Marshal(m)
|
b, err := goyaml.Marshal(m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("unable to re-serialize data %#+v: %w", m, err)
|
return nil, fmt.Errorf("unable to re-serialize data %#+v: %w", m, err)
|
||||||
}
|
}
|
||||||
|
@@ -5,7 +5,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
goyaml "github.com/go-yaml/yaml"
|
|
||||||
"github.com/goccy/go-yaml"
|
"github.com/goccy/go-yaml"
|
||||||
"github.com/xaionaro-go/datacounter"
|
"github.com/xaionaro-go/datacounter"
|
||||||
)
|
)
|
||||||
@@ -21,38 +20,11 @@ func (cfg Config) Write(b []byte) (int, error) {
|
|||||||
func (cfg Config) WriteTo(
|
func (cfg Config) WriteTo(
|
||||||
w io.Writer,
|
w io.Writer,
|
||||||
) (int64, error) {
|
) (int64, error) {
|
||||||
// There is bug in github.com/goccy/go-yaml that makes wrong intention
|
|
||||||
// in cfg.BuiltinStreamD.GitRepo.PrivateKey makes the whole value unparsable
|
|
||||||
//
|
|
||||||
// Working this around...
|
|
||||||
key := cfg.BuiltinStreamD.GitRepo.PrivateKey
|
|
||||||
cfg.BuiltinStreamD.GitRepo.PrivateKey = ""
|
|
||||||
|
|
||||||
b, err := yaml.Marshal(cfg)
|
b, err := yaml.Marshal(cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, fmt.Errorf("unable to serialize data %#+v: %w", cfg, err)
|
return 0, fmt.Errorf("unable to serialize data %#+v: %w", cfg, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
m := map[any]any{}
|
|
||||||
err = goyaml.Unmarshal(b, &m)
|
|
||||||
if err != nil {
|
|
||||||
return 0, fmt.Errorf("unable to unserialize data %s: %w", b, err)
|
|
||||||
}
|
|
||||||
if v, ok := m["streamd_builtin"]; ok {
|
|
||||||
if m2, ok := v.(map[any]any); ok {
|
|
||||||
if v, ok := m2["gitrepo"]; ok {
|
|
||||||
if m3, ok := v.(map[any]any); ok {
|
|
||||||
m3["private_key"] = key
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
b, err = goyaml.Marshal(m)
|
|
||||||
if err != nil {
|
|
||||||
return 0, fmt.Errorf("unable to re-serialize data %#+v: %w", m, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
counter := datacounter.NewWriterCounter(w)
|
counter := datacounter.NewWriterCounter(w)
|
||||||
io.Copy(counter, bytes.NewReader(b))
|
io.Copy(counter, bytes.NewReader(b))
|
||||||
return int64(counter.Count()), nil
|
return int64(counter.Count()), nil
|
||||||
|
Reference in New Issue
Block a user