schema.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // Copyright 2022 EMQ Technologies Co., Ltd.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package schema
  15. import (
  16. "fmt"
  17. "github.com/lf-edge/ekuiper/internal/pkg/def"
  18. )
  19. type Info struct {
  20. Type def.SchemaType `json:"type"`
  21. Name string `json:"name"`
  22. Content string `json:"content"`
  23. FilePath string `json:"file"`
  24. SoPath string `json:"soFile"`
  25. }
  26. func (i *Info) Validate() error {
  27. if i.Name == "" {
  28. return fmt.Errorf("name is required")
  29. }
  30. if i.Content != "" && i.FilePath != "" {
  31. return fmt.Errorf("cannot specify both content and file")
  32. }
  33. switch i.Type {
  34. case def.PROTOBUF:
  35. if i.Content == "" && i.FilePath == "" {
  36. return fmt.Errorf("must specify content or file")
  37. }
  38. case def.CUSTOM:
  39. if i.SoPath == "" {
  40. return fmt.Errorf("soFile is required")
  41. }
  42. default:
  43. return fmt.Errorf("unsupported type: %s", i.Type)
  44. }
  45. return nil
  46. }
  47. var (
  48. schemaExt = map[def.SchemaType]string{
  49. def.PROTOBUF: ".proto",
  50. }
  51. )