Skip to content

Commit

Permalink
cmd/definitions: Implement AOS-40 (#541)
Browse files Browse the repository at this point in the history
* cmd/definitions: Implement AOS-40

Signed-off-by: Xuanwo <[email protected]>

* Bump deps

Signed-off-by: Xuanwo <[email protected]>
  • Loading branch information
Xuanwo authored Apr 23, 2021
1 parent 4d27eff commit 6847a93
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 42 deletions.
6 changes: 3 additions & 3 deletions cmd/definitions/bindata.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions cmd/definitions/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ func parseFunc(name string) map[string]*templateutils.Method {
log.Fatalf("read file failed: %v", err)
}

source := &templateutils.Source{}
err = source.ParseContent(filename, content)
source, err := templateutils.ParseContent(filename, content)
if err != nil {
log.Fatalf("parse content: %v", err)
}
Expand All @@ -74,6 +73,7 @@ var typeMap = map[string]string{
"http_client_options": "*httpclient.Options",

// Compose types
"any": "interface{}",
"byte_array": "[]byte",
"string_array": "[]string",
"string_string_map": "map[string]string",
Expand Down
3 changes: 2 additions & 1 deletion cmd/definitions/tests/service.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,5 @@ type = "DefaultStoragePairs"
description = "set default pairs for storager actions"

[infos.object.meta.storage-class]
type = "string"
type = "string"
description = "is the storage class for this object"
30 changes: 24 additions & 6 deletions cmd/definitions/tmpl/service.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,38 @@ const (
{{- end }}
)

// Service available metadata.
const (
// ObjectMetadata stores service metadata for object.
type ObjectMetadata struct {
{{- range $_, $v := .Infos }}
{{- if not $v.Global }}
{{ $pname := $v.Name | toPascal }}
{{- $pname := $v.Name | toPascal }}
{{- if $v.DisplayName }}
{{ $pname = $v.DisplayName }}
{{- $pname = $v.DisplayName }}
{{- end }}
{{ $v.Description }}
Metadata{{ $pname }} = "{{ $.Name }}-{{ $v.Name }}"
{{ $pname }} {{ $v.Type }}
{{- end }}
{{- end }}
)
}

// GetObjectMetadata will get ObjectMetadata from Object.
//
// - This function should not be called by service implementer.
// - The returning ObjectMetadata is read only and should not be modified.
func GetObjectMetadata(o *Object) ObjectMetadata {
om, ok := o.GetServiceMetadata()
if ok {
return om.(ObjectMetadata)
}
return ObjectMetadata{}
}

// setObjectMetadata will set ObjectMetadata into Object.
//
// - This function should only be called once, please make sure all data has been written before set.
func setObjectMetadata(o *Object, om ObjectMetadata) {
o.SetServiceMetadata(om)
}

{{- range $_, $v := .Pairs }}
{{- if not $v.Global }}
Expand Down
2 changes: 1 addition & 1 deletion cmd/definitions/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func (i *Info) Format(s specs.Info, global bool) {
i.Name = s.Name
i.itype = s.Type
i.Export = s.Export
i.Description = s.Description
i.Description = formatDescription(templateutils.ToPascal(s.Name), s.Description)

i.Global = global
}
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ module github.com/aos-dev/go-storage/v3
go 1.15

require (
github.com/Xuanwo/templateutils v0.0.0-20201216100309-46f73cd4e4b1
github.com/aos-dev/specs/go v0.0.0-20210420062803-1a60efa2eae3
github.com/Xuanwo/templateutils v0.1.0
github.com/aos-dev/specs/go v0.0.0-20210423110314-8361397c2bf3
github.com/dave/dst v0.26.2
github.com/golang/mock v1.5.0
github.com/google/uuid v1.2.0
Expand Down
Loading

0 comments on commit 6847a93

Please sign in to comment.