1
0
mirror of https://github.com/nxshock/gron.git synced 2024-11-27 03:41:00 +05:00
gron/jobtype.go
2022-05-10 19:44:41 +05:00

38 lines
537 B
Go

package main
import (
"fmt"
"strings"
)
type JobType int
const (
Cmd JobType = iota + 1
Sql
)
func (j *JobType) MarshalText() (text []byte, err error) {
switch int(*j) {
case 1:
return []byte("cmd"), nil
case 2:
return []byte("sql"), nil
}
return nil, fmt.Errorf("unknown job type: %v", j)
}
func (j *JobType) UnmarshalText(text []byte) error {
switch strings.ToLower(string(text)) {
case "cmd":
*j = 1
return nil
case "sql":
*j = 2
return nil
}
return fmt.Errorf("unknown job type: %v", string(text))
}