Micro-service for file storage and processing written in Go
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

97 lines
1.6 KiB

  1. package pipelines
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "io/fs"
  6. "log"
  7. "os"
  8. "path/filepath"
  9. )
  10. // Pipelines
  11. const (
  12. Image PipelineType = iota
  13. Video
  14. )
  15. type PipelineType int
  16. type IPipeline interface {
  17. GetName() string
  18. GetSlug() string
  19. GetType() PipelineType
  20. GetSteps() []Step
  21. }
  22. type Pipeline struct {
  23. Name string `json:"name" faker:"name"`
  24. Slug string `json:"slug" faker:"word"`
  25. Type PipelineType `json:"type" faker:"-"`
  26. RemoveMetadata bool `json:"remove_metadata" faker:"-"`
  27. Steps []Step `json:"steps" faker:"-"`
  28. }
  29. func (p Pipeline) GetName() string {
  30. return p.Name
  31. }
  32. func (p Pipeline) GetSlug() string {
  33. return p.Slug
  34. }
  35. func (p Pipeline) GetType() PipelineType {
  36. return p.Type
  37. }
  38. func (p Pipeline) GetSteps() []Step {
  39. return p.Steps
  40. }
  41. type ImagePipeline struct {
  42. Pipeline
  43. }
  44. type VideoPipeline struct {
  45. Pipeline
  46. }
  47. // Deserialization
  48. func DeserializePipelines(pipelines [][]byte) []IPipeline {
  49. var values []IPipeline
  50. for _, pipeline := range pipelines {
  51. var deserializedObject Pipeline
  52. err := json.Unmarshal(pipeline, &deserializedObject)
  53. if err != nil {
  54. log.Fatalf("Could not deserialize pipelines config: %s", err)
  55. }
  56. values = append(values, deserializedObject)
  57. }
  58. return values
  59. }
  60. func LoadPipelines() []IPipeline {
  61. var files [][]byte
  62. path, _ := os.Getwd()
  63. err := filepath.Walk(path+"/config", func(path string, info fs.FileInfo, err error) error {
  64. if err == nil && info.IsDir() == false {
  65. fmt.Println(path)
  66. data, _ := os.ReadFile(path)
  67. files = append(files, data)
  68. }
  69. return nil
  70. })
  71. if err != nil {
  72. panic(err)
  73. }
  74. return DeserializePipelines(files)
  75. }