mirror of
https://github.com/wneessen/niljson.git
synced 2024-11-22 05:30:49 +01:00
Refactor data processing and message formatting
Updated the JSON data structure for better readability and added more comprehensive output formatting in the main function. Utilized a single 'output' string to accumulate messages, improving code readability and efficiency.
This commit is contained in:
parent
ab747282c8
commit
bdd7efec82
1 changed files with 30 additions and 19 deletions
25
README.md
25
README.md
|
@ -56,25 +56,36 @@ type JSONType struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
data := []byte(`{"string":"test", "int":123, "int64": 12345678901234, "float64":0, "nil":null, "bool":true}`)
|
data := []byte(`{
|
||||||
|
"bytes": "Ynl0ZXM=",
|
||||||
|
"bool": true,
|
||||||
|
"float32": null,
|
||||||
|
"float64":0,
|
||||||
|
"int": 123,
|
||||||
|
"int64": 12345678901234,
|
||||||
|
"nilvalue": null,
|
||||||
|
"string":"test"
|
||||||
|
}`)
|
||||||
|
|
||||||
var example JSONType
|
var example JSONType
|
||||||
|
var output string
|
||||||
if err := json.Unmarshal(data, &example); err != nil {
|
if err := json.Unmarshal(data, &example); err != nil {
|
||||||
fmt.Println("failed to unmarshal JSON:", err)
|
fmt.Println("failed to unmarshal JSON:", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
if example.Bool.NotNil() {
|
if example.Bool.NotNil() {
|
||||||
fmt.Printf("Bool is: %t\n", example.Bool.Value())
|
output += fmt.Sprintf("Bool is: %t, ", example.Bool.Value())
|
||||||
}
|
}
|
||||||
if example.Float64.IsNil() {
|
if example.Float32.IsNil() {
|
||||||
fmt.Println("Float 32 is NIL")
|
output += "Float 32 is nil, "
|
||||||
}
|
}
|
||||||
if example.Float64.NotNil() {
|
if example.Float64.NotNil() {
|
||||||
fmt.Printf("Float is: %f\n", example.Float64.Value())
|
output += fmt.Sprintf("Float 64 is: %f, ", example.Float64.Value())
|
||||||
}
|
}
|
||||||
if !example.String.IsNil() {
|
if example.String.NotNil() {
|
||||||
fmt.Printf("String is: %s\n", example.String.Value())
|
output += fmt.Sprintf("String is: %s", example.String.Value())
|
||||||
}
|
}
|
||||||
|
fmt.Println(output)
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
Loading…
Reference in a new issue