MCPcopy Create free account
hub / github.com/cronitorio/cronitor-cli / getMonitorRequestBody

Function getMonitorRequestBody

cmd/monitor.go:797–833  ·  view source on GitHub ↗

Helper functions

()

Source from the content-addressed store, hash-verified

795
796// Helper functions
797func getMonitorRequestBody() ([]byte, error) {
798 if monitorData != "" && monitorFile != "" {
799 return nil, errors.New("cannot specify both --data and --file")
800 }
801
802 if monitorData != "" {
803 // Try JSON first
804 var js json.RawMessage
805 if err := json.Unmarshal([]byte(monitorData), &js); err != nil {
806 // Might be YAML, return as-is
807 return []byte(monitorData), nil
808 }
809 return []byte(monitorData), nil
810 }
811
812 if monitorFile != "" {
813 data, err := os.ReadFile(monitorFile)
814 if err != nil {
815 return nil, fmt.Errorf("failed to read file: %w", err)
816 }
817 return data, nil
818 }
819
820 // Try stdin
821 stat, _ := os.Stdin.Stat()
822 if (stat.Mode() & os.ModeCharDevice) == 0 {
823 data, err := os.ReadFile("/dev/stdin")
824 if err != nil {
825 return nil, fmt.Errorf("failed to read stdin: %w", err)
826 }
827 if len(data) > 0 {
828 return data, nil
829 }
830 }
831
832 return nil, nil
833}
834
835func outputToTarget(content string) {
836 if monitorOutput != "" {

Callers 1

monitor.goFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected