update
continuous-integration/drone/tag Build is failing
Details
continuous-integration/drone/tag Build is failing
Details
parent
9eb285bfe8
commit
735ca0ed93
22
README.md
22
README.md
|
@ -2,6 +2,28 @@
|
|||
|
||||
a json config visualizer
|
||||
|
||||
## Usage
|
||||
|
||||
```shell
|
||||
Usage: kconfig [options]
|
||||
-addr string
|
||||
address to listen (default ":8000")
|
||||
-dev
|
||||
turn on dev mode
|
||||
-f string
|
||||
file to use as schema, if will watch file change every 120ms
|
||||
-level int
|
||||
log level [-1(trace):5(panic)] 7 to disable (default 1)
|
||||
-name string
|
||||
name of the app (default "kconfig")
|
||||
-pretty
|
||||
log message in human readable format (the original log is json)
|
||||
```
|
||||
|
||||
### Example
|
||||
|
||||
`kconfig -addr 127.0.0.1:8000 -pretty -level 0 -f dist/test.jcs`
|
||||
|
||||
## Schema
|
||||
|
||||
JSON Schema Support
|
||||
|
|
|
@ -3,8 +3,10 @@ package main
|
|||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/rs/zerolog"
|
||||
"github.com/rs/zerolog/log"
|
||||
|
@ -13,6 +15,11 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
Version = "0.0.0"
|
||||
Build = "alpha"
|
||||
flagVer bool
|
||||
|
||||
flagFile string
|
||||
flagAddr string
|
||||
flagAppName string
|
||||
|
||||
|
@ -22,11 +29,14 @@ var (
|
|||
)
|
||||
|
||||
func init() {
|
||||
flag.BoolVar(&flagVer, "v", false, "show version")
|
||||
|
||||
flag.StringVar(&flagFile, "f", "", "file to use as schema, if will watch file change every 120ms")
|
||||
flag.StringVar(&flagAddr, "addr", ":8000", "address to listen")
|
||||
flag.StringVar(&flagAppName, "name", "kconfig", "name of the app")
|
||||
|
||||
flag.BoolVar(&flagDev, "dev", false, "turn on dev mode")
|
||||
flag.IntVar(&flagLogLevel, "level", 1, "log level [-1:5] 7 to disable")
|
||||
flag.IntVar(&flagLogLevel, "level", 1, "log level [-1(trace):5(panic)] 7 to disable")
|
||||
flag.BoolVar(&flagLogPretty, "pretty", false, "log message in human readable format (the original log is json)")
|
||||
|
||||
flag.Usage = func() {
|
||||
|
@ -36,6 +46,10 @@ func init() {
|
|||
}
|
||||
func main() {
|
||||
flag.Parse()
|
||||
if flagVer {
|
||||
fmt.Printf("%v - %v\n", Version, Build)
|
||||
return
|
||||
}
|
||||
zerolog.TimeFieldFormat = zerolog.TimeFormatUnix
|
||||
zerolog.SetGlobalLevel(zerolog.Level(flagLogLevel))
|
||||
if flagLogPretty {
|
||||
|
@ -49,8 +63,39 @@ func main() {
|
|||
}
|
||||
|
||||
mux := http.NewServeMux()
|
||||
// mux.Handle("/k/", http.StripPrefix("/k", kconfig.New()))
|
||||
mux.Handle("/", kconfig.New())
|
||||
k := kconfig.New()
|
||||
if flagFile != "" {
|
||||
go func() {
|
||||
fi, err := os.Stat(flagFile)
|
||||
if err != nil {
|
||||
log.Panic().Err(err).Msg("")
|
||||
}
|
||||
last := fi.ModTime().Add(-time.Second)
|
||||
for {
|
||||
fi, err := os.Stat(flagFile)
|
||||
if err != nil {
|
||||
log.Panic().Err(err).Msg("")
|
||||
}
|
||||
if fi.ModTime().After(last) {
|
||||
last = fi.ModTime()
|
||||
file, err := os.Open(flagFile)
|
||||
if err != nil {
|
||||
log.Panic().Err(err).Msg("")
|
||||
}
|
||||
schema, err := ioutil.ReadAll(file)
|
||||
if err != nil {
|
||||
log.Panic().Err(err).Msg("")
|
||||
}
|
||||
k.KFJstr = schema
|
||||
}
|
||||
<-time.After(time.Millisecond * 120)
|
||||
}
|
||||
}()
|
||||
}
|
||||
k.Apply = func(b []byte) error { return fmt.Errorf("error %s", "test") }
|
||||
|
||||
// mux.Handle("/k/", http.StripPrefix("/k", k))
|
||||
mux.Handle("/", k)
|
||||
|
||||
g := guard.New()
|
||||
|
||||
|
|
|
@ -12,8 +12,8 @@ import (
|
|||
"kumoly.io/tools/kconfig/public"
|
||||
)
|
||||
|
||||
//go:embed assets/default.kfj
|
||||
var defaultSchema string
|
||||
//go:embed assets/default.jcs
|
||||
var defaultSchema []byte
|
||||
|
||||
//go:embed public/index.html
|
||||
var index string
|
||||
|
@ -27,7 +27,7 @@ func init() {
|
|||
|
||||
type Kconfig struct {
|
||||
AppName string
|
||||
KFJstr string
|
||||
KFJstr []byte
|
||||
Mux *http.ServeMux
|
||||
|
||||
Apply func([]byte) error
|
||||
|
|
5
main.js
5
main.js
|
@ -31,6 +31,8 @@ import 'spectre.css/dist/spectre-icons.min.css'
|
|||
}).catch(err=>{console.log(err);return;});
|
||||
if (!res.ok) {
|
||||
console.log(res)
|
||||
const errMsg = await res.text()
|
||||
alert(errMsg)
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -39,6 +41,9 @@ import 'spectre.css/dist/spectre-icons.min.css'
|
|||
const res = await fetch('api/load').catch(err=>{console.log(err);return;});
|
||||
if (!res.ok) {
|
||||
console.log(res)
|
||||
const errMsg = await res.text()
|
||||
alert(errMsg)
|
||||
return
|
||||
}
|
||||
const body = await res.json();
|
||||
editor.setValue(body);
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -1 +1 @@
|
|||
<!DOCTYPE html><html><head><link rel="stylesheet" href="index.e0891ed3.css"><title>{{.AppName}}</title><style>.ace_selection{background:#7f7f00!important}</style></head><body> <div class="container" style="max-width:960px;"> <div class="columns"> <h1 class="col-md-12">{{.AppName}} Config</h1> </div> <div class="columns"> <div class="col-md-12 column"> <button id="submit" class="tiny">Submit</button> <button id="load" class="secondary tiny">Load</button> <button id="download" class="secondary tiny">Download</button> <a id="downloadAnchorElem" style="display:none"></a> <span id="valid_indicator" class="label"></span> </div> </div> <br> <div class="columns"> <div class="col-md-12 column" id="editor_holder"></div> </div> </div> <script type="module" src="index.2e4018f1.js"></script> {{.ACE_JS}} <script>let AppName="{{.AppName}}";</script> </body></html>
|
||||
<!DOCTYPE html><html><head><link rel="stylesheet" href="index.e0891ed3.css"><title>{{.AppName}}</title><style>.ace_selection{background:#7f7f00!important}</style></head><body> <div class="container" style="max-width:960px;"> <div class="columns"> <h1 class="col-md-12">{{.AppName}} Config</h1> </div> <div class="columns"> <div class="col-md-12 column"> <button id="submit" class="tiny">Submit</button> <button id="load" class="secondary tiny">Load</button> <button id="download" class="secondary tiny">Download</button> <a id="downloadAnchorElem" style="display:none"></a> <span id="valid_indicator" class="label"></span> </div> </div> <br> <div class="columns"> <div class="col-md-12 column" id="editor_holder"></div> </div> </div> <script type="module" src="index.5a7c0711.js"></script> {{.ACE_JS}} <script>let AppName="{{.AppName}}";</script> </body></html>
|
Loading…
Reference in New Issue