本文整理匯總了Golang中github.com/elodina/go-avro.Schema類的典型用法代碼示例。如果您正苦於以下問題:Golang Schema類的具體用法?Golang Schema怎麽用?Golang Schema使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Schema類的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: GetVersion
func (this *CachedSchemaRegistryClient) GetVersion(subject string, schema avro.Schema) (int32, error) {
var schemaVersionMap map[avro.Schema]int32
var exists bool
if schemaVersionMap, exists = this.versionCache[subject]; !exists {
schemaVersionMap = make(map[avro.Schema]int32)
this.versionCache[subject] = schemaVersionMap
}
var version int32
if version, exists = schemaVersionMap[schema]; exists {
return version, nil
}
request, err := this.newDefaultRequest("POST",
fmt.Sprintf(CHECK_IS_REGISTERED, subject),
strings.NewReader(fmt.Sprintf("{\"schema\": %s}", strconv.Quote(schema.String()))))
response, err := http.DefaultClient.Do(request)
if err != nil {
return 0, err
}
if this.isOK(response) {
decodedResponse := &GetSubjectVersionResponse{}
if this.handleSuccess(response, decodedResponse) != nil {
return 0, err
}
schemaVersionMap[schema] = decodedResponse.Version
return decodedResponse.Version, err
} else {
return 0, this.handleError(response)
}
}
示例2: Register
func (this *CachedSchemaRegistryClient) Register(subject string, schema avro.Schema) (int32, error) {
var schemaIdMap map[avro.Schema]int32
var exists bool
if schemaIdMap, exists = this.schemaCache[subject]; !exists {
schemaIdMap = make(map[avro.Schema]int32)
this.schemaCache[subject] = schemaIdMap
}
var id int32
if id, exists = schemaIdMap[schema]; exists {
return id, nil
}
request, err := this.newDefaultRequest("POST",
fmt.Sprintf(REGISTER_NEW_SCHEMA, subject),
strings.NewReader(fmt.Sprintf("{\"schema\": %s}", strconv.Quote(schema.String()))))
response, err := http.DefaultClient.Do(request)
if err != nil {
return 0, err
}
if this.isOK(response) {
decodedResponse := &RegisterSchemaResponse{}
if this.handleSuccess(response, decodedResponse) != nil {
return 0, err
}
schemaIdMap[schema] = decodedResponse.Id
this.idCache[decodedResponse.Id] = schema
return decodedResponse.Id, err
} else {
return 0, this.handleError(response)
}
}