Documentation
¶
Index ¶
Examples ¶
Constants ¶
View Source
const PathDefault = "default"
PathDefault is a fake path to the default config.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { // Path to the config. Path string `json:"-"` Fields []Field `json:"fields" validate:"min=1"` }
Config contains application customization settings.
func GetDefaultConfig ¶
func GetDefaultConfig() *Config
GetDefaultConfig returns the configuration with default values.
Example ¶
package main import ( "bytes" "encoding/json" "fmt" "log" "github.com/hedhyw/json-log-viewer/internal/pkg/config" ) func main() { cfg := config.GetDefaultConfig() var buf bytes.Buffer jsonEncoder := json.NewEncoder(&buf) jsonEncoder.SetIndent("", "\t") if err := jsonEncoder.Encode(&cfg); err != nil { log.Fatal(err) } fmt.Println(buf.String()) }
Output: { "fields": [ { "title": "Time", "kind": "numerictime", "ref": [ "$.timestamp", "$.time", "$.t", "$.ts" ], "width": 30 }, { "title": "Level", "kind": "level", "ref": [ "$.level", "$.lvl", "$.l" ], "width": 10 }, { "title": "Message", "kind": "message", "ref": [ "$.message", "$.msg", "$.error", "$.err" ], "width": 0 } ] }
type Field ¶
type Field struct { Title string `json:"title" validate:"required,min=1,max=32"` Kind FieldKind `json:"kind" validate:"required,oneof=time message numerictime secondtime millitime microtime level any"` References []string `json:"ref" validate:"min=1,dive,required"` Width int `json:"width" validate:"min=0"` }
Field customization.
type FieldKind ¶
type FieldKind string
FieldKind describes the type of the log field.
const ( FieldKindTime FieldKind = "time" FieldKindNumericTime FieldKind = "numerictime" FieldKindSecondTime FieldKind = "secondtime" FieldKindMilliTime FieldKind = "millitime" FieldKindMicroTime FieldKind = "microtime" FieldKindMessage FieldKind = "message" FieldKindLevel FieldKind = "level" FieldKindAny FieldKind = "any" )
Possible kinds.
Click to show internal directories.
Click to hide internal directories.