Skip to content

Instantly share code, notes, and snippets.

@nexssp
Created July 20, 2020 17:05
Show Gist options
  • Save nexssp/017f5086d589b00510bf0a3a4cf270c1 to your computer and use it in GitHub Desktop.
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
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