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.

71 lines
1.1 KiB

  1. package main
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "io/fs"
  6. "os"
  7. "path/filepath"
  8. )
  9. var Pipelines []Pipeline
  10. type PipelineType int
  11. type PipelineStepType int
  12. const (
  13. Image PipelineType = iota
  14. Video
  15. )
  16. const (
  17. Resize PipelineStepType = iota
  18. Compress
  19. Encode
  20. )
  21. type Pipeline struct {
  22. Name string
  23. Type PipelineType
  24. RemoveMetadata bool
  25. Steps []Step
  26. }
  27. type Step struct {
  28. Name string
  29. Type PipelineStepType
  30. }
  31. func DeserializePipelines(pipelines [][]byte) []Pipeline {
  32. values := make([]Pipeline, len(pipelines))
  33. for index, pipeline := range pipelines {
  34. var deserializedObject Pipeline
  35. json.Unmarshal(pipeline, &deserializedObject)
  36. values[index] = deserializedObject
  37. }
  38. return values
  39. }
  40. func LoadPipelines() {
  41. var files [][]byte
  42. path, _ := os.Getwd()
  43. err := filepath.Walk(path+"/pipelines", func(path string, info fs.FileInfo, err error) error {
  44. if err == nil && info.IsDir() == false {
  45. fmt.Println(path)
  46. data, _ := os.ReadFile(path)
  47. files = append(files, data)
  48. }
  49. return nil
  50. })
  51. if err != nil {
  52. panic(err)
  53. }
  54. Pipelines = DeserializePipelines(files)
  55. }