You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
rwxrob-dot/scripts/goprintasjson

28 lines
715 B
Bash

#!/usr/bin/env bash
read -r name
echo "
// ---------------------------- PrintAsJSON ---------------------------
func (s *$name) MarshalJSON() ([]byte, error) {
buf := ""
// TODO
return []byte(buf),nil
}
// JSON implements PrintAsJSON multi-line, 2-space indent JSON output.
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()}
// Print implements PrintAsJSON.
func (s *$name) Print() { fmt.Println(s.JSON()) }
// Log implements PrintAsJSON.
func (s $name) Log() { log.Print(s.JSON()) }
"