Files
api/models/log-importer.go
T
2020-08-20 20:58:16 +02:00

52 lines
1.2 KiB
Go

package models
import (
"fmt"
"io"
"strconv"
)
// LogImporter describes a model related log importing.
type LogImporter string
const (
// LogImporterMircLike is a value of LogImporter
LogImporterMircLike LogImporter = "MircLike"
// LogImporterForumLog is a value of LogImporter
LogImporterForumLog LogImporter = "ForumLog"
// LogImporterForumLog is a value of LogImporter
LogImporterIrcCloud LogImporter = "IrcCloud"
)
// IsValid returns true if the underlying string is one of the correct values.
func (e LogImporter) IsValid() bool {
switch e {
case LogImporterForumLog, LogImporterMircLike, LogImporterIrcCloud:
return true
}
return false
}
func (e LogImporter) String() string {
return string(e)
}
// UnmarshalGQL unmarshals the underlying graphql value.
func (e *LogImporter) UnmarshalGQL(v interface{}) error {
str, ok := v.(string)
if !ok {
return fmt.Errorf("enums must be strings")
}
*e = LogImporter(str)
if !e.IsValid() {
return fmt.Errorf("%s is not a valid LogImporter", str)
}
return nil
}
// MarshalGQL marshals the underlying graphql value.
func (e LogImporter) MarshalGQL(w io.Writer) {
fmt.Fprint(w, strconv.Quote(e.String()))
}