-
Notifications
You must be signed in to change notification settings - Fork 353
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
backend: add endpoint to create new schema
- Loading branch information
Showing
7 changed files
with
185 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Copyright 2023 Redpanda Data, Inc. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.md | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0 | ||
|
||
package schema | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
// SchemaType as an enum representing schema types. The default schema type | ||
// is avro. | ||
type SchemaType int | ||
|
||
const ( | ||
TypeAvro SchemaType = iota | ||
TypeProtobuf | ||
TypeJSON | ||
) | ||
|
||
// String presentation of schema type. | ||
func (t SchemaType) String() string { | ||
switch t { | ||
case TypeAvro: | ||
return "AVRO" | ||
case TypeProtobuf: | ||
return "PROTOBUF" | ||
case TypeJSON: | ||
return "JSON" | ||
default: | ||
return "" | ||
} | ||
} | ||
|
||
// MarshalText marshals the SchemaType. | ||
func (t SchemaType) MarshalText() ([]byte, error) { | ||
s := t.String() | ||
if s == "" { | ||
return nil, fmt.Errorf("unknown schema type %d", t) | ||
} | ||
return []byte(s), nil | ||
} | ||
|
||
// UnmarshalText unmarshals the schema type. | ||
func (t *SchemaType) UnmarshalText(text []byte) error { | ||
switch s := strings.ToUpper(string(text)); s { | ||
default: | ||
return fmt.Errorf("unknown schema type %q", s) | ||
case "", "AVRO": | ||
*t = TypeAvro | ||
case "PROTOBUF": | ||
*t = TypeProtobuf | ||
case "JSON": | ||
*t = TypeJSON | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters