rwxrob-dot/scripts/goprintasjson

28 lines
715 B
Plaintext
Raw Normal View History

2022-03-01 23:04:20 +00:00
#!/usr/bin/env bash
read -r name
echo "
2022-03-02 02:11:19 +00:00
// ---------------------------- PrintAsJSON ---------------------------
2022-03-02 02:24:27 +00:00
func (s *$name) MarshalJSON() ([]byte, error) {
2022-03-01 23:04:20 +00:00
buf := ""
// TODO
return []byte(buf),nil
}
// JSON implements PrintAsJSON multi-line, 2-space indent JSON output.
2022-03-02 02:24:27 +00:00
func (s *$name) JSON() string {b,_ :=s.MarshalJSON();return string(b)}
func (s *$name) JSON() string {b,_ :=json.Marshal(s);return string(b)}
// String implements PrintAsJSON and fmt.Stringer interface as JSON.
func (s $name) String() string {return s.JSON()}
2022-03-01 23:04:20 +00:00
// Print implements PrintAsJSON.
2022-03-02 02:24:27 +00:00
func (s *$name) Print() { fmt.Println(s.JSON()) }
2022-03-01 23:04:20 +00:00
// Log implements PrintAsJSON.
func (s $name) Log() { log.Print(s.JSON()) }
"