Skip to content

Commit

Permalink
add interface getters
Browse files Browse the repository at this point in the history
  • Loading branch information
Myriad-Dreamin committed Jul 9, 2020
1 parent 76955d0 commit 3707337
Show file tree
Hide file tree
Showing 11 changed files with 105 additions and 14 deletions.
31 changes: 24 additions & 7 deletions artisan-concept-interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ type CategoryDescription interface {
GetObjects() []ObjectDescription
}

type MethodType int

type MethodDescription interface {
GetMethodType() MethodType
GetName() string
Expand All @@ -35,9 +37,12 @@ type MethodDescription interface {

type Type = fmt.Stringer
type ObjectDescription interface {
DebuggerObject

GetUUID() UUID
GenObjectTmpl() ObjTmpl
GetType() Type
GetName() string
GetEmbedObject() []ObjectDescription
}

Expand Down Expand Up @@ -72,42 +77,54 @@ type ProposingService interface {
GetFilePath() string
}

type MethodType int
type CategoryGetter interface {
GetName() string
GetPath() string
GetMethods() []Method
GetWildObjects() []SerializeObject
ForEachSubCate(func(path string, cat Category) (shouldStop bool)) error
}

// todo middleware
type Category interface {
WithName(name string) Category
Path(path string) Category
SubCate(path string, cat Category) Category
DiveIn(path string) Category

RawMethod(m ...Method) Category
Method(m MethodType, descriptions ...interface{}) Category

Object(descriptions ...interface{}) Category
AppendObject(objs ...SerializeObject) Category
Object(descriptions ...interface{}) Category

GetPath() string
CategoryGetter

CreateCategoryDescription(ctx *Context) CategoryDescription

HelpWrapObjectXXX(skip int, descriptions ...interface{}) Category
}

type Method interface {
GetMethodType() MethodType
GetName() string
GetRequestProtocols() []SerializeObject
GetResponseProtocols() []SerializeObject

CreateMethodDescription(ctx *Context) *methodDescription
}

type DebuggerObject interface {
DefiningPosition() string
}

type SerializeObject interface {
DebuggerObject

GetName() string
CreateObjectDescription(ctx *Context) ObjectDescription
}

type Parameter interface {
CreateParameterDescription(ctx *Context) ParameterDescription
}

type DebuggerObject interface {
DefiningPosition() string
}
9 changes: 9 additions & 0 deletions description-object.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package artisan

type objectDescription struct {
name string
dp string
uuid UUID
params []ParameterDescription
}
Expand All @@ -14,6 +15,14 @@ func (desc objectDescription) GetType() Type {
return pureType{typeString: desc.name}
}

func (desc objectDescription) GetName() string {
return desc.name
}

func (desc objectDescription) DefiningPosition() string {
return desc.dp
}

func (desc objectDescription) GetUUID() UUID {
return desc.uuid
}
Expand Down
37 changes: 33 additions & 4 deletions draft-category.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package artisan

type category struct {
name string
path string
methods []Method
wildObjects []SerializeObject
Expand All @@ -11,6 +12,36 @@ func newCategory() *category {
return new(category)
}

func (c *category) GetName() string {
return c.name
}

func (c *category) GetPath() string {
return c.path
}

func (c *category) GetMethods() []Method {
return c.methods
}

func (c *category) GetWildObjects() []SerializeObject {
return c.wildObjects
}

func (c *category) ForEachSubCate(mapFunc func(path string, cat Category) (shouldStop bool)) error {
for k, v := range c.subs {
if !mapFunc(k, v) {
return ErrorStopped
}
}
return nil
}

func (c *category) WithName(name string) Category {
c.name = name
return c
}

func (c *category) Path(path string) Category {
c.path = path
return c
Expand All @@ -32,10 +63,6 @@ func (c *category) DiveIn(path string) Category {
return cat
}

func (c *category) GetPath() string {
return c.path
}

func (c *category) RawMethod(m ...Method) Category {
c.methods = append(c.methods, m...)
return c
Expand Down Expand Up @@ -89,5 +116,7 @@ func (c *category) CreateCategoryDescription(ctx *Context) CategoryDescription {
subDesc := sub.CreateCategoryDescription(ctx.Sub())
desc.subCates[subDesc.GetName()] = subDesc
}
desc.name = c.name
desc.path = c.path
return desc
}
12 changes: 12 additions & 0 deletions draft-method.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@ func (method method) GetName() string {
return method.name
}

func (method method) GetMethodType() MethodType {
return method.methodType
}

func (method method) GetRequestProtocols() []SerializeObject {
return method.requests
}

func (method method) GetResponseProtocols() []SerializeObject {
return method.replies
}

func newMethod(methodType MethodType) *method {
return &method{methodType: methodType}
}
Expand Down
5 changes: 5 additions & 0 deletions errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package artisan

import "errors"

var ErrorStopped = errors.New("stopped")
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,6 @@ github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R
github.com/prometheus/procfs v0.0.0-20190117184657-bf6a532e95b1/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww=
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
Expand Down
6 changes: 5 additions & 1 deletion type-inherit-class.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ type inheritClass struct {
dp string
}

func (i inheritClass) GetName() string {
return i.name
}

func (i inheritClass) DefiningPosition() string {
return i.dp
}
Expand Down Expand Up @@ -36,6 +40,6 @@ func (i inheritClass) GetEmbedObject() []ObjectDescription {
return nil
}

func (i inheritClass) CreateObjectDescription(ctx *Context) ObjectDescription {
func (i inheritClass) CreateObjectDescription(*Context) ObjectDescription {
return i
}
4 changes: 4 additions & 0 deletions type-reply-object.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ type ReplyObject struct {
s SerializeObject
}

func (r ReplyObject) GetName() string {
return r.s.GetName()
}

func (r ReplyObject) DefiningPosition() string {
return r.s.DefiningPosition()
}
Expand Down
4 changes: 4 additions & 0 deletions type-request-object.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ type RequestObject struct {
s SerializeObject
}

func (r RequestObject) GetName() string {
return r.s.GetName()
}

func (r RequestObject) DefiningPosition() string {
return r.s.DefiningPosition()
}
Expand Down
5 changes: 5 additions & 0 deletions type-serialize-object.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ func (obj *serializeObject) DefiningPosition() string {
return obj.dp
}

func (obj *serializeObject) GetName() string {
return obj.name
}

func (obj serializeObject) GetUUID() UUID {
return obj.uuid
}
Expand All @@ -44,6 +48,7 @@ func (obj *serializeObject) CreateObjectDescription(ctx *Context) ObjectDescript
desc.params = append(desc.params, param.CreateParameterDescription(ctx))
}
desc.name = obj.name
desc.dp = obj.dp
if len(desc.name) == 0 {
if suf := ctx.Get("obj_suf"); suf != nil {
if suf, ok := suf.(string); ok {
Expand Down
4 changes: 4 additions & 0 deletions type-transfer-class.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ func (i transferClass) DefiningPosition() string {
return i.dp
}

func (i transferClass) GetName() string {
return i.name
}

func (i transferClass) CreateObjectDescription(ctx *Context) ObjectDescription {
ctx.AppendPackage(reflect.TypeOf(i.base).PkgPath())
return i
Expand Down

0 comments on commit 3707337

Please sign in to comment.