mirror of
https://github.com/aykhans/bsky-feedgen.git
synced 2025-07-17 21:34:00 +00:00
🦋
This commit is contained in:
50
pkg/types/consumer_cursor.go
Normal file
50
pkg/types/consumer_cursor.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package types
|
||||
|
||||
import "fmt"
|
||||
|
||||
type ConsumerCursor string
|
||||
|
||||
var (
|
||||
ConsumerCursorLastConsumed ConsumerCursor = "last-consumed"
|
||||
ConsumerCursorFirstStream ConsumerCursor = "first-stream"
|
||||
ConsumerCursorCurrentStream ConsumerCursor = "current-stream"
|
||||
)
|
||||
|
||||
func (c ConsumerCursor) String() string {
|
||||
return string(c)
|
||||
}
|
||||
|
||||
func (c ConsumerCursor) IsValid() bool {
|
||||
return c == ConsumerCursorLastConsumed || c == ConsumerCursorFirstStream || c == ConsumerCursorCurrentStream
|
||||
}
|
||||
|
||||
func (c ConsumerCursor) Equal(other ConsumerCursor) bool {
|
||||
return c == other
|
||||
}
|
||||
|
||||
func (c ConsumerCursor) IsLastConsumed() bool {
|
||||
return c == ConsumerCursorLastConsumed
|
||||
}
|
||||
|
||||
func (c ConsumerCursor) IsFirstStream() bool {
|
||||
return c == ConsumerCursorFirstStream
|
||||
}
|
||||
|
||||
func (c ConsumerCursor) IsCurrentStream() bool {
|
||||
return c == ConsumerCursorCurrentStream
|
||||
}
|
||||
|
||||
func (c *ConsumerCursor) Set(value string) error {
|
||||
switch value {
|
||||
case ConsumerCursorLastConsumed.String(), "":
|
||||
*c = ConsumerCursorLastConsumed
|
||||
case ConsumerCursorFirstStream.String():
|
||||
*c = ConsumerCursorFirstStream
|
||||
case ConsumerCursorCurrentStream.String():
|
||||
*c = ConsumerCursorCurrentStream
|
||||
default:
|
||||
return fmt.Errorf("invalid cursor value: %s", value)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
18
pkg/types/err_map.go
Normal file
18
pkg/types/err_map.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package types
|
||||
|
||||
type ErrMap map[string]error
|
||||
|
||||
func (ErrMap ErrMap) ToStringMap() map[string]string {
|
||||
if len(ErrMap) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
stringMap := make(map[string]string)
|
||||
for key, err := range ErrMap {
|
||||
if err != nil {
|
||||
stringMap[key] = err.Error()
|
||||
}
|
||||
}
|
||||
|
||||
return stringMap
|
||||
}
|
7
pkg/types/errors.go
Normal file
7
pkg/types/errors.go
Normal file
@@ -0,0 +1,7 @@
|
||||
package types
|
||||
|
||||
import "errors"
|
||||
|
||||
var (
|
||||
ErrInternal = errors.New("internal error")
|
||||
)
|
43
pkg/types/generator_cursor.go
Normal file
43
pkg/types/generator_cursor.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package types
|
||||
|
||||
import "fmt"
|
||||
|
||||
type GeneratorCursor string
|
||||
|
||||
var (
|
||||
GeneratorCursorLastGenerated GeneratorCursor = "last-generated"
|
||||
GeneratorCursorFirstPost GeneratorCursor = "first-post"
|
||||
)
|
||||
|
||||
func (c GeneratorCursor) String() string {
|
||||
return string(c)
|
||||
}
|
||||
|
||||
func (c GeneratorCursor) IsValid() bool {
|
||||
return c == GeneratorCursorLastGenerated || c == GeneratorCursorFirstPost
|
||||
}
|
||||
|
||||
func (c GeneratorCursor) Equal(other GeneratorCursor) bool {
|
||||
return c == other
|
||||
}
|
||||
|
||||
func (c GeneratorCursor) IsLastGenerated() bool {
|
||||
return c == GeneratorCursorLastGenerated
|
||||
}
|
||||
|
||||
func (c GeneratorCursor) IsFirstPost() bool {
|
||||
return c == GeneratorCursorFirstPost
|
||||
}
|
||||
|
||||
func (c *GeneratorCursor) Set(value string) error {
|
||||
switch value {
|
||||
case GeneratorCursorLastGenerated.String(), "":
|
||||
*c = GeneratorCursorLastGenerated
|
||||
case GeneratorCursorFirstPost.String():
|
||||
*c = GeneratorCursorFirstPost
|
||||
default:
|
||||
return fmt.Errorf("invalid cursor value: %s", value)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
Reference in New Issue
Block a user