Created
July 20, 2020 17:05
-
-
Save nexssp/017f5086d589b00510bf0a3a4cf270c1 to your computer and use it in GitHub Desktop.
Read JSON from STDIN, add go version to the JSON and printout to STDOUT the JSON string - Nexss Programmer HelloWorld.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"bufio" | |
"encoding/json" | |
"fmt" | |
"os" | |
"runtime" | |
) | |
func main() { | |
scanner := bufio.NewScanner(os.Stdin) | |
var res map[string]interface{} | |
for scanner.Scan() { | |
if err := json.Unmarshal([]byte(scanner.Text()), &res); err != nil { | |
panic(err) | |
} | |
res["HelloFromGo"] = runtime.Version() | |
NexssStdout, _ := json.Marshal(res) | |
fmt.Println(string(NexssStdout)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment