diff options
author | Valentin Rothberg <rothberg@redhat.com> | 2019-06-24 11:29:13 +0200 |
---|---|---|
committer | Valentin Rothberg <rothberg@redhat.com> | 2019-06-24 13:20:59 +0200 |
commit | d697456dc90adbaf68224ed7c115b38d5855e582 (patch) | |
tree | 5fd88c48b34e7bead0028fa97e39f43f03880642 /vendor/github.com/varlink/go/cmd | |
parent | a3211b73c62a9fcc13f09305bf629ef507b26d34 (diff) | |
download | podman-d697456dc90adbaf68224ed7c115b38d5855e582.tar.gz podman-d697456dc90adbaf68224ed7c115b38d5855e582.tar.bz2 podman-d697456dc90adbaf68224ed7c115b38d5855e582.zip |
migrate to go-modules
Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
Diffstat (limited to 'vendor/github.com/varlink/go/cmd')
6 files changed, 0 insertions, 1268 deletions
diff --git a/vendor/github.com/varlink/go/cmd/varlink-go-certification/main.go b/vendor/github.com/varlink/go/cmd/varlink-go-certification/main.go deleted file mode 100644 index dfffb5d0d..000000000 --- a/vendor/github.com/varlink/go/cmd/varlink-go-certification/main.go +++ /dev/null @@ -1,619 +0,0 @@ -package main - -import ( - "crypto/rand" - "encoding/json" - "flag" - "fmt" - "github.com/varlink/go/cmd/varlink-go-certification/orgvarlinkcertification" - "github.com/varlink/go/varlink" - "io" - "math" - "os" - "strconv" - "sync" - "time" -) - -func run_client(address string) { - c, err := varlink.NewConnection(address) - if err != nil { - fmt.Println("Failed to connect") - return - } - defer c.Close() - - client_id, err := orgvarlinkcertification.Start().Call(c) - if err != nil { - fmt.Println("Start() failed") - return - } - fmt.Printf("Start: '%v'\n", client_id) - - b1, err := orgvarlinkcertification.Test01().Call(c, client_id) - if err != nil { - fmt.Println("Test01() failed") - return - } - fmt.Printf("Test01: '%v'\n", b1) - - i2, err := orgvarlinkcertification.Test02().Call(c, client_id, b1) - if err != nil { - fmt.Println("Test02() failed") - return - } - fmt.Printf("Test02: '%v'\n", i2) - - f3, err := orgvarlinkcertification.Test03().Call(c, client_id, i2) - if err != nil { - fmt.Println("Test03() failed") - return - } - fmt.Printf("Test03: '%v'\n", f3) - - s4, err := orgvarlinkcertification.Test04().Call(c, client_id, f3) - if err != nil { - fmt.Println("Test04() failed") - return - } - fmt.Printf("Test04: '%v'\n", s4) - - b5, i5, f5, s5, err := orgvarlinkcertification.Test05().Call(c, client_id, s4) - if err != nil { - fmt.Println("Test05() failed") - return - } - fmt.Printf("Test05: '%v'\n", b5) - - o6, err := orgvarlinkcertification.Test06().Call(c, client_id, b5, i5, f5, s5) - if err != nil { - fmt.Println("Test06() failed") - return - } - fmt.Printf("Test06: '%v'\n", o6) - - m7, err := orgvarlinkcertification.Test07().Call(c, client_id, o6) - if err != nil { - fmt.Println("Test07() failed") - return - } - fmt.Printf("Test07: '%v'\n", m7) - - m8, err := orgvarlinkcertification.Test08().Call(c, client_id, m7) - if err != nil { - fmt.Println("Test08() failed") - return - } - fmt.Printf("Test08: '%v'\n", m8) - - t9, err := orgvarlinkcertification.Test09().Call(c, client_id, m8) - if err != nil { - fmt.Println("Test09() failed") - return - } - fmt.Printf("Test09: '%v'\n", t9) - - receive10, err := orgvarlinkcertification.Test10().Send(c, varlink.More, client_id, t9) - if err != nil { - fmt.Println("Test10() failed") - return - } - - fmt.Println("Test10() Send:") - var a10 []string - for { - s10, flags10, err := receive10() - if err != nil { - fmt.Println("Test10() receive failed") - return - } - a10 = append(a10, s10) - fmt.Printf(" Receive: '%v'\n", s10) - - if flags10&varlink.Continues == 0 { - break - } - } - fmt.Printf("Test10: '%v'\n", a10) - - _, err = orgvarlinkcertification.Test11().Send(c, varlink.Oneway, client_id, a10) - if err != nil { - fmt.Println("Test11() failed") - return - } - fmt.Println("Test11: ''") - - end, err := orgvarlinkcertification.End().Call(c, client_id) - if err != nil { - fmt.Println("End() failed") - return - } - fmt.Printf("End: '%v'\n", end) -} - -// Service -type client struct { - id string - time time.Time -} - -type test struct { - orgvarlinkcertification.VarlinkInterface - mutex sync.Mutex - clients map[string]*client -} - -func (t *test) Client(id string) *client { - t.mutex.Lock() - defer t.mutex.Unlock() - - return t.clients[id] -} - -func (t *test) NewClient() *client { - id128 := make([]byte, 16) - io.ReadFull(rand.Reader, id128) - id128[8] = id128[8]&^0xc0 | 0x80 - id128[6] = id128[6]&^0xf0 | 0x40 - uuid := fmt.Sprintf("%x-%x-%x-%x-%x", id128[0:4], id128[4:6], id128[6:8], id128[8:10], id128[10:]) - - t.mutex.Lock() - defer t.mutex.Unlock() - - // Garbage-collect old clients - for key, client := range t.clients { - if time.Since(client.time).Minutes() > 1 { - delete(t.clients, key) - } - } - - if len(t.clients) > 100 { - return nil - } - - c := client{ - id: uuid, - time: time.Now(), - } - t.clients[uuid] = &c - - return &c -} - -func (t *test) RemoveClient(id string) { - t.mutex.Lock() - defer t.mutex.Unlock() - - delete(t.clients, id) -} - -func (t *test) Start(c orgvarlinkcertification.VarlinkCall) error { - return c.ReplyStart(t.NewClient().id) -} - -func (t *test) Test01(c orgvarlinkcertification.VarlinkCall, client_id_ string) error { - if t.Client(client_id_) == nil { - return c.ReplyClientIdError() - } - - return c.ReplyTest01(true) -} - -func (t *test) Test02(c orgvarlinkcertification.VarlinkCall, client_id_ string, bool_ bool) error { - if t.Client(client_id_) == nil { - return c.ReplyClientIdError() - } - - if !bool_ { - return c.ReplyCertificationError(nil, nil) - } - - return c.ReplyTest02(1) -} - -func (t *test) Test03(c orgvarlinkcertification.VarlinkCall, client_id_ string, int_ int64) error { - if t.Client(client_id_) == nil { - return c.ReplyClientIdError() - } - - if int_ != 1 { - return c.ReplyCertificationError(nil, nil) - } - - return c.ReplyTest03(1.0) -} - -func (t *test) Test04(c orgvarlinkcertification.VarlinkCall, client_id_ string, float_ float64) error { - if t.Client(client_id_) == nil { - return c.ReplyClientIdError() - } - - if float_ != 1.0 { - return c.ReplyCertificationError(nil, nil) - } - - return c.ReplyTest04("ping") -} -func (t *test) Test05(c orgvarlinkcertification.VarlinkCall, client_id_ string, string_ string) error { - if t.Client(client_id_) == nil { - return c.ReplyClientIdError() - } - - if string_ != "ping" { - return c.ReplyCertificationError(nil, nil) - } - - return c.ReplyTest05(false, 2, math.Pi, "a lot of string") -} - -func (t *test) Test06(c orgvarlinkcertification.VarlinkCall, client_id_ string, bool_ bool, int_ int64, float_ float64, string_ string) error { - if t.Client(client_id_) == nil { - return c.ReplyClientIdError() - } - - if bool_ { - return c.ReplyCertificationError(nil, nil) - } - - if int_ != 2 { - return c.ReplyCertificationError(nil, nil) - } - - if float_ != math.Pi { - return c.ReplyCertificationError(nil, nil) - } - - if string_ != "a lot of string" { - return c.ReplyCertificationError(nil, nil) - } - - s := struct { - Bool bool - Int int64 - Float float64 - String string - }{ - Bool: false, - Int: 2, - Float: math.Pi, - String: "a lot of string", - } - return c.ReplyTest06(s) -} - -func (t *test) Test07(c orgvarlinkcertification.VarlinkCall, client_id_ string, struct_ struct { - Bool bool - Int int64 - Float float64 - String string -}) error { - if t.Client(client_id_) == nil { - return c.ReplyClientIdError() - } - - if struct_.Bool { - return c.ReplyCertificationError(nil, nil) - } - - if struct_.Int != 2 { - return c.ReplyCertificationError(nil, nil) - } - - if struct_.Float != math.Pi { - return c.ReplyCertificationError(nil, nil) - } - - if struct_.String != "a lot of string" { - return c.ReplyCertificationError(nil, nil) - } - - m := map[string]string{ - "bar": "Bar", - "foo": "Foo", - } - return c.ReplyTest07(m) -} - -func (t *test) Test08(c orgvarlinkcertification.VarlinkCall, client_id_ string, map_ map[string]string) error { - if t.Client(client_id_) == nil { - return c.ReplyClientIdError() - } - - if len(map_) != 2 { - return c.ReplyCertificationError(nil, nil) - } - - if map_["bar"] != "Bar" { - return c.ReplyCertificationError(nil, nil) - } - - if map_["foo"] != "Foo" { - return c.ReplyCertificationError(nil, nil) - } - - m := map[string]struct{}{ - "one": {}, - "two": {}, - "three": {}, - } - return c.ReplyTest08(m) -} - -func (t *test) Test09(c orgvarlinkcertification.VarlinkCall, client_id_ string, set_ map[string]struct{}) error { - if t.Client(client_id_) == nil { - return c.ReplyClientIdError() - } - - if len(set_) != 3 { - return c.ReplyCertificationError(nil, nil) - } - - _, ok := set_["one"] - if !ok { - return c.ReplyCertificationError(nil, nil) - } - - _, ok = set_["two"] - if !ok { - return c.ReplyCertificationError(nil, nil) - } - - _, ok = set_["three"] - if !ok { - return c.ReplyCertificationError(nil, nil) - } - - m := orgvarlinkcertification.MyType{ - Object: json.RawMessage(`{"method": "org.varlink.certification.Test09", "parameters": {"map": {"foo": "Foo", "bar": "Bar"}}}`), - Enum: "two", - Struct: struct { - First int64 `json:"first"` - Second string `json:"second"` - }{First: 1, Second: "2"}, - Array: []string{"one", "two", "three"}, - Dictionary: map[string]string{"foo": "Foo", "bar": "Bar"}, - Stringset: map[string]struct{}{"one": {}, "two": {}, "three": {}}, - Nullable: nil, - Nullable_array_struct: nil, - Interface: orgvarlinkcertification.Interface{ - Foo: &[]*map[string]string{ - nil, - &map[string]string{"Foo": "foo", "Bar": "bar"}, - nil, - &map[string]string{"one": "foo", "two": "bar"}, - }, - Anon: struct { - Foo bool `json:"foo"` - Bar bool `json:"bar"` - }{Foo: true, Bar: false}, - }, - } - return c.ReplyTest09(m) -} - -func (t *test) Test10(c orgvarlinkcertification.VarlinkCall, client_id_ string, mytype_ orgvarlinkcertification.MyType) error { - if t.Client(client_id_) == nil { - return c.ReplyClientIdError() - } - - var o struct { - Method string `json:"method"` - Parameters struct { - Map map[string]string `json:"map"` - } `json:"parameters"` - } - err := json.Unmarshal(mytype_.Object, &o) - if err != nil { - return err - } - - if o.Method != "org.varlink.certification.Test09" { - return c.ReplyCertificationError(nil, nil) - } - - if len(o.Parameters.Map) != 2 { - return c.ReplyCertificationError(nil, nil) - } - - if o.Parameters.Map["bar"] != "Bar" { - return c.ReplyCertificationError(nil, nil) - } - - if o.Parameters.Map["foo"] != "Foo" { - return c.ReplyCertificationError(nil, nil) - } - - if mytype_.Enum != "two" { - return c.ReplyCertificationError(nil, nil) - } - - if mytype_.Struct.First != 1 { - return c.ReplyCertificationError(nil, nil) - } - - if mytype_.Struct.Second != "2" { - return c.ReplyCertificationError(nil, nil) - } - - if len(mytype_.Array) != 3 { - return c.ReplyCertificationError(nil, nil) - } - - if mytype_.Array[0] != "one" && mytype_.Array[1] != "two" && mytype_.Array[2] != "three" { - return c.ReplyCertificationError(nil, nil) - } - - if len(mytype_.Dictionary) != 2 { - return c.ReplyCertificationError(nil, nil) - } - - if mytype_.Dictionary["bar"] != "Bar" { - return c.ReplyCertificationError(nil, nil) - } - - if mytype_.Dictionary["foo"] != "Foo" { - return c.ReplyCertificationError(nil, nil) - } - - if len(mytype_.Stringset) != 3 { - return c.ReplyCertificationError(nil, nil) - } - - _, ok := mytype_.Stringset["one"] - if !ok { - return c.ReplyCertificationError(nil, nil) - } - - _, ok = mytype_.Stringset["two"] - if !ok { - return c.ReplyCertificationError(nil, nil) - } - - _, ok = mytype_.Stringset["three"] - if !ok { - return c.ReplyCertificationError(nil, nil) - } - - if mytype_.Nullable != nil { - return c.ReplyCertificationError(nil, nil) - } - - if mytype_.Nullable_array_struct != nil { - return c.ReplyCertificationError(nil, nil) - } - - i := *mytype_.Interface.Foo - if len(i) != 4 { - return c.ReplyCertificationError(nil, nil) - } - - if i[0] != nil { - return c.ReplyCertificationError(nil, nil) - } - - if len(*i[1]) != 2 { - return c.ReplyCertificationError(nil, nil) - } - - if (*i[1])["Foo"] != "foo" { - return c.ReplyCertificationError(nil, nil) - } - - if (*i[1])["Bar"] != "bar" { - return c.ReplyCertificationError(nil, nil) - } - - if i[2] != nil { - return c.ReplyCertificationError(nil, nil) - } - - if len(*i[3]) != 2 { - return c.ReplyCertificationError(nil, nil) - } - - if (*i[3])["one"] != "foo" { - return c.ReplyCertificationError(nil, nil) - } - - if (*i[3])["two"] != "bar" { - return c.ReplyCertificationError(nil, nil) - } - - if !mytype_.Interface.Anon.Foo { - return c.ReplyCertificationError(nil, nil) - } - - if mytype_.Interface.Anon.Bar { - return c.ReplyCertificationError(nil, nil) - } - - if !c.WantsMore() { - return c.ReplyCertificationError(nil, nil) - } - - for i := 1; i <= 10; i++ { - c.Continues = i < 10 - err := c.ReplyTest10("Reply number " + strconv.Itoa(i)) - if err != nil { - return err - } - } - - return nil -} - -func (t *test) Test11(c orgvarlinkcertification.VarlinkCall, client_id_ string, last_more_replies_ []string) error { - if t.Client(client_id_) == nil { - return c.ReplyClientIdError() - } - - if len(last_more_replies_) != 10 { - return c.ReplyCertificationError(nil, nil) - } - - if !c.IsOneway() { - return c.ReplyCertificationError(nil, nil) - } - - for i := 1; i <= 10; i++ { - if last_more_replies_[i] != "Reply number "+strconv.Itoa(i) { - return c.ReplyCertificationError(nil, nil) - } - } - - return c.ReplyTest11() -} - -func (t *test) End(c orgvarlinkcertification.VarlinkCall, client_id_ string) error { - if t.Client(client_id_) == nil { - return c.ReplyClientIdError() - } - - t.RemoveClient(client_id_) - return c.ReplyEnd(true) -} - -func run_server(address string) { - t := test{ - clients: make(map[string]*client), - } - - s, err := varlink.NewService( - "Varlink", - "Certification", - "1", - "https://github.com/varlink/go", - ) - if err != nil { - fmt.Println(err) - os.Exit(1) - } - - s.RegisterInterface(orgvarlinkcertification.VarlinkNew(&t)) - err = s.Listen(address, 0) - if err != nil { - fmt.Println(err) - os.Exit(1) - } -} - -func main() { - var address string - var client bool - - flag.StringVar(&address, "varlink", "", "Varlink address") - flag.BoolVar(&client, "client", false, "Run as client") - flag.Parse() - - if address == "" { - flag.Usage() - os.Exit(1) - } - - if client { - run_client(address) - return - } - - run_server(address) -} diff --git a/vendor/github.com/varlink/go/cmd/varlink-go-certification/orgvarlinkcertification/generate.go b/vendor/github.com/varlink/go/cmd/varlink-go-certification/orgvarlinkcertification/generate.go deleted file mode 100644 index e1ac7f090..000000000 --- a/vendor/github.com/varlink/go/cmd/varlink-go-certification/orgvarlinkcertification/generate.go +++ /dev/null @@ -1,3 +0,0 @@ -package orgvarlinkcertification - -//go:generate go run ../../varlink-go-interface-generator/main.go org.varlink.certification.varlink diff --git a/vendor/github.com/varlink/go/cmd/varlink-go-certification/orgvarlinkcertification/org.varlink.certification.varlink b/vendor/github.com/varlink/go/cmd/varlink-go-certification/orgvarlinkcertification/org.varlink.certification.varlink deleted file mode 100644 index 41b9967b5..000000000 --- a/vendor/github.com/varlink/go/cmd/varlink-go-certification/orgvarlinkcertification/org.varlink.certification.varlink +++ /dev/null @@ -1,89 +0,0 @@ -# Interface to test varlink implementations against. -# First you write a varlink client calling: -# Start, Test01, Test02, …, Test09, End -# The return value of the previous call should be the argument of the next call. -# Then you test this client against well known servers like python or rust from -# https://github.com/varlink/ -# -# Next you write a varlink server providing the same service as the well known ones. -# Now run your client against it and run well known clients like python or rust -# from https://github.com/varlink/ against your server. If all works out, then -# your new language bindings should be varlink certified. -interface org.varlink.certification - -type Interface ( - foo: ?[]?[string](foo, bar, baz), - anon: (foo: bool, bar: bool) -) - -type MyType ( - object: object, - enum: (one, two, three), - struct: (first: int, second: string), - array: []string, - dictionary: [string]string, - stringset: [string](), - nullable: ?string, - nullable_array_struct: ?[](first: int, second: string), - interface: Interface -) - -method Start() -> (client_id: string) - -method Test01(client_id: string) -> (bool: bool) - -method Test02(client_id: string, bool: bool) -> (int: int) - -method Test03(client_id: string, int: int) -> (float: float) - -method Test04(client_id: string, float: float) -> (string: string) - -method Test05(client_id: string, string: string) -> ( - bool: bool, - int: int, - float: float, - string: string -) - -method Test06( - client_id: string, - bool: bool, - int: int, - float: float, - string: string -) -> ( - struct: ( - bool: bool, - int: int, - float: float, - string: string - ) -) - -method Test07( - client_id: string, - struct: ( - bool: bool, - int: int, - float: float, - string: string - ) -) -> (map: [string]string) - -method Test08(client_id: string, map: [string]string) -> (set: [string]()) - -method Test09(client_id: string, set: [string]()) -> (mytype: MyType) - -# returns more than one reply with "continues" -method Test10(client_id: string, mytype: MyType) -> (string: string) - -method Test11( - client_id: string, - last_more_replies: []string -) -> () - -method End(client_id: string) -> (all_ok: bool) - -error ClientIdError () - -error CertificationError (wants: object, got: object) diff --git a/vendor/github.com/varlink/go/cmd/varlink-go-interface-generator/generator_test.go b/vendor/github.com/varlink/go/cmd/varlink-go-interface-generator/generator_test.go deleted file mode 100644 index 8e749f411..000000000 --- a/vendor/github.com/varlink/go/cmd/varlink-go-interface-generator/generator_test.go +++ /dev/null @@ -1,90 +0,0 @@ -package main - -import ( - "strings" - "testing" -) - -func expect(t *testing.T, expected string, returned string) { - if strings.Compare(returned, expected) != 0 { - t.Fatalf("Expected(%d): `%s`\nGot(%d): `%s`\n", - len(expected), expected, - len(returned), returned) - } -} - -func TestIDLParser(t *testing.T) { - pkgname, b, err := generateTemplate(` -# Interface to jump a spacecraft to another point in space. The -# FTL Drive is the propulsion system to achieve faster-than-light -# travel through space. A ship making a properly calculated -# jump can arrive safely in planetary orbit, or alongside other -# ships or spaceborne objects. -interface org.example.ftl - -# The current state of the FTL drive and the amount of fuel -# available to jump. -type DriveCondition ( - state: (idle, spooling, busy), - booster: bool, - active_engines: [](id: int, state: bool), - tylium_level: int -) - -# Speed, trajectory and jump duration is calculated prior to -# activating the FTL drive. -type DriveConfiguration ( - speed: int, - trajectory: int, - duration: int -) - -# The galactic coordinates use the Sun as the origin. Galactic -# longitude is measured with primary direction from the Sun to -# the center of the galaxy in the galactic plane, while the -# galactic latitude measures the angle of the object above the -# galactic plane. -type Coordinate ( - longitude: float, - latitude: float, - distance: int -) - -# Monitor the drive. The method will reply with an update whenever -# the drive's state changes -method Monitor() -> (condition: DriveCondition) - -# Calculate the drive's jump parameters from the current -# position to the target position in the galaxy -method CalculateConfiguration( - current: Coordinate, - target: Coordinate -) -> (configuration: DriveConfiguration) - -# Jump to the calculated point in space -method Jump(configuration: DriveConfiguration) -> () - -# There is not enough tylium to jump with the given parameters -error NotEnoughEnergy () - -# The supplied parameters are outside the supported range -error ParameterOutOfRange (field: string) - -# some more coverage -method Foo(interface: string) -> (ret: (go: string, switch: bool, more: (t:bool, f:bool))) - -# some more coverage -method TestMap(map: [string]string) -> (map: [string](i: int, val: string)) -method TestSet(set: [string]()) -> (set: [string]()) -method TestObject(object: object) -> (object: object) - `) - - if err != nil { - t.Fatalf("Error parsing %v", err) - } - expect(t, "orgexampleftl", pkgname) - if len(b) <= 0 { - t.Fatal("No generated go source") - } - // FIXME: compare b.String() against expected output -} diff --git a/vendor/github.com/varlink/go/cmd/varlink-go-type-generator/main.go b/vendor/github.com/varlink/go/cmd/varlink-go-type-generator/main.go deleted file mode 100644 index 46414b7bf..000000000 --- a/vendor/github.com/varlink/go/cmd/varlink-go-type-generator/main.go +++ /dev/null @@ -1,172 +0,0 @@ -package main - -import ( - "fmt" - "go/ast" - "go/importer" - "go/parser" - "go/token" - "go/types" - "log" - "os" -) - -func IsBasicGoType(t types.Type, flag types.BasicInfo) bool { - switch u := t.(type) { - case *types.Basic: - if u.Info()&flag != 0 { - return true - } - return false - case *types.Named: - return IsBasicGoType(u.Underlying(), flag) - } - return false -} - -func GoToVarlinkType(t types.Type) string { - if IsBasicGoType(t, types.IsBoolean) { - return "bool" - } - - if IsBasicGoType(t, types.IsInteger) { - return "int" - } - - if IsBasicGoType(t, types.IsFloat) { - return "float" - } - - if IsBasicGoType(t, types.IsString) { - return "string" - } - - switch u := t.(type) { - case *types.Basic: - return fmt.Sprintf("<<<%s>>>", t.String()) - - case *types.Named: - return u.Obj().Name() - - case *types.Map: - if IsBasicGoType(u.Key(), types.IsString) { - return fmt.Sprintf("[string]%s", GoToVarlinkType(u.Elem())) - } else { - return fmt.Sprintf("<<<%s>>>", u.String()) - } - - case *types.Interface: - if u.Empty() { - return "()" - } - return fmt.Sprintf("<<<%s>>>", u.String()) - - case *types.Pointer: - return fmt.Sprintf("?%s", GoToVarlinkType(u.Elem())) - - case *types.Array: - return fmt.Sprintf("[]%s", GoToVarlinkType(u.Elem())) - - case *types.Slice: - return fmt.Sprintf("[]%s", GoToVarlinkType(u.Elem())) - - case *types.Struct: - if u.NumFields() > 0 { - s := "" - for i := 0; i < u.NumFields(); i++ { - if i > 0 { - s += ",\n" - } - s += fmt.Sprintf("\t%s: %s", - u.Field(i).Name(), GoToVarlinkType(u.Field(i).Type())) - } - - return fmt.Sprintf("(\n%s\n)", s) - } - return "()" - - default: - return fmt.Sprintf("<<<%T %s>>>", t, u) - } -} - -func PrintDefsUses(name string, fset *token.FileSet, files []*ast.File) error { - conf := types.Config{ - Importer: importer.Default(), - FakeImportC: true, - } - - info := &types.Info{ - Defs: make(map[*ast.Ident]types.Object), - } - - _, err := conf.Check(name, fset, files, info) - if err != nil { - return err // type error - } - - seen := map[string]interface{}{} - - for id, obj := range info.Defs { - if obj == nil { - continue - } - - if _, ok := seen[id.Name]; ok { - continue - } - - /* - if !obj.Exported() || obj.Pkg().Name() != name { - continue - } - */ - switch f := obj.Type().Underlying().(type) { - case *types.Struct: - if f.NumFields() > 0 { - fmt.Printf("type %s %s\n\n", id.Name, GoToVarlinkType(f)) - } - } - seen[id.Name] = nil - } - - return nil -} - -func main() { - - path := os.Args[1] - fs := token.NewFileSet() - - if stat, err := os.Stat(path); err == nil && stat.IsDir() { - pkgs, err := parser.ParseDir(fs, path, nil, 0) - if err != nil { - fmt.Printf("parsing dir '%s': %s", path, err) - } - for name, pkg := range pkgs { - log.Println("Found package:", name) - - fset := make([]*ast.File, len(pkg.Files), len(pkg.Files)) - idx := 0 - for _, value := range pkg.Files { - fset[idx] = value - idx++ - } - - if err := PrintDefsUses(name, fs, fset); err != nil { - log.Print(err) // type error - } - } - } else { - - fset, err := parser.ParseFile(fs, path, nil, 0) - - if err != nil { - fmt.Printf("parsing file '%s': %s", path, err) - } - name := fset.Name.String() - if err := PrintDefsUses(name, fs, []*ast.File{fset}); err != nil { - log.Print(err) // type error - } - } -} diff --git a/vendor/github.com/varlink/go/cmd/varlink/main.go b/vendor/github.com/varlink/go/cmd/varlink/main.go deleted file mode 100644 index 6781dd956..000000000 --- a/vendor/github.com/varlink/go/cmd/varlink/main.go +++ /dev/null @@ -1,295 +0,0 @@ -package main - -import ( - "encoding/json" - "flag" - "fmt" - "github.com/TylerBrock/colorjson" - "github.com/fatih/color" - "github.com/varlink/go/varlink" - "os" - "strings" -) - -var bold = color.New(color.Bold) -var errorBoldRed string -var bridge string - -func ErrPrintf(format string, a ...interface{}) { - fmt.Fprintf(os.Stderr, "%s ", errorBoldRed) - fmt.Fprintf(os.Stderr, format, a...) -} - -func print_usage(set *flag.FlagSet, arg_help string) { - if set == nil { - fmt.Fprintf(os.Stderr, "Usage: %s [GLOBAL OPTIONS] COMMAND ...\n", os.Args[0]) - } else { - fmt.Fprintf(os.Stderr, "Usage: %s [GLOBAL OPTIONS] %s [OPTIONS] %s\n", os.Args[0], set.Name(), arg_help) - } - - fmt.Fprintln(os.Stderr, "\nGlobal Options:") - flag.PrintDefaults() - - if set == nil { - fmt.Fprintln(os.Stderr, "\nCommands:") - fmt.Fprintln(os.Stderr, " info\tPrint information about a service") - fmt.Fprintln(os.Stderr, " help\tPrint interface description or service information") - fmt.Fprintln(os.Stderr, " call\tCall a method") - } else { - fmt.Fprintln(os.Stderr, "\nOptions:") - set.PrintDefaults() - } - os.Exit(1) -} - -func varlink_call(args []string) { - var err error - var oneway bool - - callFlags := flag.NewFlagSet("help", flag.ExitOnError) - callFlags.BoolVar(&oneway, "-oneway", false, "Use bridge for connection") - var help bool - callFlags.BoolVar(&help, "help", false, "Prints help information") - var usage = func() { print_usage(callFlags, "<[ADDRESS/]INTERFACE.METHOD> [ARGUMENTS]") } - callFlags.Usage = usage - - _ = callFlags.Parse(args) - - if help { - usage() - } - - var con *varlink.Connection - var address string - var methodName string - - if len(bridge) != 0 { - con, err = varlink.NewBridge(bridge) - - if err != nil { - ErrPrintf("Cannot connect with bridge '%s': %v\n", bridge, err) - os.Exit(2) - } - address = "bridge:" + bridge - methodName = callFlags.Arg(0) - } else { - uri := callFlags.Arg(0) - if uri == "" { - usage() - } - - li := strings.LastIndex(uri, "/") - - if li == -1 { - ErrPrintf("Invalid address '%s'\n", uri) - os.Exit(2) - } - - address = uri[:li] - methodName = uri[li+1:] - - con, err = varlink.NewConnection(address) - - if err != nil { - ErrPrintf("Cannot connect to '%s': %v\n", address, err) - os.Exit(2) - } - } - var parameters string - var params json.RawMessage - - parameters = callFlags.Arg(1) - if parameters == "" { - params = nil - } else { - json.Unmarshal([]byte(parameters), ¶ms) - } - - var flags uint64 - flags = 0 - if oneway { - flags |= varlink.Oneway - } - recv, err := con.Send(methodName, params, flags) - - var retval map[string]interface{} - - // FIXME: Use cont - _, err = recv(&retval) - - f := colorjson.NewFormatter() - f.Indent = 2 - f.KeyColor = color.New(color.FgCyan) - f.StringColor = color.New(color.FgMagenta) - f.NumberColor = color.New(color.FgMagenta) - f.BoolColor = color.New(color.FgMagenta) - f.NullColor = color.New(color.FgMagenta) - - if err != nil { - if e, ok := err.(*varlink.Error); ok { - ErrPrintf("Call failed with error: %v\n", color.New(color.FgRed).Sprint(e.Name)) - errorRawParameters := e.Parameters.(*json.RawMessage) - if errorRawParameters != nil { - var param map[string]interface{} - _ = json.Unmarshal(*errorRawParameters, ¶m) - c, _ := f.Marshal(param) - fmt.Fprintf(os.Stderr, "%v\n", string(c)) - } - os.Exit(2) - } - ErrPrintf("Error calling '%s': %v\n", methodName, err) - os.Exit(2) - } - c, _ := f.Marshal(retval) - fmt.Println(string(c)) -} - -func varlink_help(args []string) { - var err error - - helpFlags := flag.NewFlagSet("help", flag.ExitOnError) - var help bool - helpFlags.BoolVar(&help, "help", false, "Prints help information") - var usage = func() { print_usage(helpFlags, "<[ADDRESS/]INTERFACE>") } - helpFlags.Usage = usage - - _ = helpFlags.Parse(args) - - if help { - usage() - } - - var con *varlink.Connection - var address string - var interfaceName string - - if len(bridge) != 0 { - con, err = varlink.NewBridge(bridge) - - if err != nil { - ErrPrintf("Cannot connect with bridge '%s': %v\n", bridge, err) - os.Exit(2) - } - address = "bridge:" + bridge - interfaceName = helpFlags.Arg(0) - } else { - uri := helpFlags.Arg(0) - if uri == "" && bridge == "" { - ErrPrintf("No ADDRESS or activation or bridge\n\n") - usage() - } - - li := strings.LastIndex(uri, "/") - - if li == -1 { - ErrPrintf("Invalid address '%s'\n", uri) - os.Exit(2) - } - - address = uri[:li] - - con, err = varlink.NewConnection(address) - - if err != nil { - ErrPrintf("Cannot connect to '%s': %v\n", address, err) - os.Exit(2) - } - - interfaceName = uri[li+1:] - } - description, err := con.GetInterfaceDescription(interfaceName) - - if err != nil { - ErrPrintf("Cannot get interface description for '%s': %v\n", interfaceName, err) - os.Exit(2) - } - - fmt.Println(description) -} - -func varlink_info(args []string) { - var err error - infoFlags := flag.NewFlagSet("info", flag.ExitOnError) - var help bool - infoFlags.BoolVar(&help, "help", false, "Prints help information") - var usage = func() { print_usage(infoFlags, "[ADDRESS]") } - infoFlags.Usage = usage - - _ = infoFlags.Parse(args) - - if help { - usage() - } - - var con *varlink.Connection - var address string - - if len(bridge) != 0 { - con, err = varlink.NewBridge(bridge) - - if err != nil { - ErrPrintf("Cannot connect with bridge '%s': %v\n", bridge, err) - os.Exit(2) - } - address = "bridge:" + bridge - } else { - address = infoFlags.Arg(0) - - if address == "" && bridge == "" { - ErrPrintf("No ADDRESS or activation or bridge\n\n") - usage() - } - - con, err = varlink.NewConnection(address) - - if err != nil { - ErrPrintf("Cannot connect to '%s': %v\n", address, err) - os.Exit(2) - } - } - - var vendor, product, version, url string - var interfaces []string - - err = con.GetInfo(&vendor, &product, &version, &url, &interfaces) - - if err != nil { - ErrPrintf("Cannot get info for '%s': %v\n", address, err) - os.Exit(2) - } - - fmt.Printf("%s %s\n", bold.Sprint("Vendor:"), vendor) - fmt.Printf("%s %s\n", bold.Sprint("Product:"), product) - fmt.Printf("%s %s\n", bold.Sprint("Version:"), version) - fmt.Printf("%s %s\n", bold.Sprint("URL:"), url) - fmt.Printf("%s\n %s\n\n", bold.Sprint("Interfaces:"), strings.Join(interfaces[:], "\n ")) -} - -func main() { - var debug bool - var colorMode string - - flag.CommandLine.Usage = func() { print_usage(nil, "") } - flag.BoolVar(&debug, "debug", false, "Enable debug output") - flag.StringVar(&bridge, "bridge", "", "Use bridge for connection") - flag.StringVar(&colorMode, "color", "auto", "colorize output [default: auto] [possible values: on, off, auto]") - - flag.Parse() - - if colorMode != "on" && (os.Getenv("TERM") == "" || colorMode == "off") { - color.NoColor = true // disables colorized output - } - - errorBoldRed = bold.Sprint(color.New(color.FgRed).Sprint("Error:")) - - switch flag.Arg(0) { - case "info": - varlink_info(flag.Args()[1:]) - case "help": - varlink_help(flag.Args()[1:]) - case "call": - varlink_call(flag.Args()[1:]) - default: - print_usage(nil, "") - } -} |