当前位置: 首页>>代码示例>>Golang>>正文


Golang kite.New函数代码示例

本文整理汇总了Golang中github.com/koding/kite.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了New函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: init

func init() {
	lf := kite.New("logfetcher", "0.0.1")
	lf.Config.DisableAuthentication = true
	lf.Config.Port = 3639
	lf.HandleFunc("tail", Tail)

	go lf.Run()
	<-lf.ServerReadyNotify()

	remoteKite := kite.New("remote", "0.0.1")
	remoteKite.Config.Username = "remote"
	remote = remoteKite.NewClient("http://127.0.0.1:3639/kite")
	err := remote.Dial()
	if err != nil {
		log.Fatalf("err")
	}

	remoteKite2 := kite.New("remote2", "0.0.1")
	remoteKite2.Config.Username = "remote2"
	remote2 = remoteKite2.NewClient("http://127.0.0.1:3639/kite")
	err = remote2.Dial()
	if err != nil {
		log.Fatalf("err")
	}
}
开发者ID:koding,项目名称:koding,代码行数:25,代码来源:logfetcher_test.go

示例2: TestKitePingerPing

func TestKitePingerPing(tt *testing.T) {
	Convey("Given a KitePinger", tt, func() {
		r := kite.New("remote", "0.0.0")
		r.Config.DisableAuthentication = true
		go r.Run()
		<-r.ServerReadyNotify()

		kiteURL := fmt.Sprintf("http://127.0.0.1:%d/kite", r.Port())

		var shouldPingError bool
		r.HandleFunc("kite.ping", func(req *kite.Request) (interface{}, error) {
			if shouldPingError {
				return nil, errors.New("shouldPingError=true")
			}

			return "pong", nil
		})

		Convey("When it can communicate with remote", func() {
			l := kite.New("local", "0.0.0").NewClient(kiteURL)
			So(l.Dial(), ShouldBeNil)
			p := NewKitePinger(l)

			Convey("It should return success", func() {
				So(p.Ping(), ShouldEqual, Success)
			})
		})

		Convey("When the kite is not dialed", func() {
			l := kite.New("local", "0.0.0").NewClient(kiteURL)
			p := NewKitePinger(l)

			Convey("It should return failure", func() {
				So(p.Ping(), ShouldEqual, Failure)
			})
		})

		Convey("When the remote kite returns an error", func() {
			shouldPingError = true
			l := kite.New("local", "0.0.0").NewClient(kiteURL)
			So(l.Dial(), ShouldBeNil)
			p := NewKitePinger(l)

			Convey("It should return failure", func() {
				So(p.Ping(), ShouldEqual, Failure)
			})
		})

		Convey("When the kite url is not responding", func() {
			l := kite.New("local", "0.0.0").NewClient(kiteURL)
			So(l.Dial(), ShouldBeNil)
			r.Close()
			p := NewKitePinger(l)

			Convey("It should return failure", func() {
				So(p.Ping(), ShouldEqual, Failure)
			})
		})
	})
}
开发者ID:koding,项目名称:koding,代码行数:60,代码来源:kitepinger_test.go

示例3: init

func init() {
	storageKite = kite.New("storageKite", "0.0.1")
	storageKite.Config.DisableAuthentication = true
	storageKite.Config.Port = 3637

	u, err := user.Current()
	if err != nil {
		panic(err)
	}

	db, err := openBoltDb(filepath.Join(u.HomeDir, "/.config/koding/klient.bolt"))
	if err != nil {
		log.Println("Can't use BoltDB: ", err)
	}

	s := New(db)

	storageKite.HandleFunc("get", s.GetValue)
	storageKite.HandleFunc("set", s.SetValue)
	storageKite.HandleFunc("delete", s.DeleteValue)

	go storageKite.Run()
	<-storageKite.ServerReadyNotify()

	remoteKite := kite.New("remote", "0.0.1")
	remoteKite.Config.Username = u.Username
	remote = remoteKite.NewClient("http://127.0.0.1:3637/kite")
	err = remote.Dial()
	if err != nil {
		log.Fatalf("err")
	}
}
开发者ID:koding,项目名称:koding,代码行数:32,代码来源:storage_test.go

示例4: TestMain

func TestMain(m *testing.M) {
	flag.Parse()
	kiteURL := testutil.GenKiteURL()

	sshkeys = kite.New("sshkeys", "0.0.1")
	sshkeys.Config.DisableAuthentication = true
	sshkeys.Config.Port = kiteURL.Port()
	sshkeys.HandleFunc("list", List)
	sshkeys.HandleFunc("add", Add)
	sshkeys.HandleFunc("delete", Delete)

	go sshkeys.Run()
	<-sshkeys.ServerReadyNotify()
	defer sshkeys.Close()

	u, err := user.Current()
	if err != nil {
		panic(err)
	}

	remoteKite := kite.New("remote", "0.0.1")
	remoteKite.Config.Username = u.Username
	remote = remoteKite.NewClient(kiteURL.String())
	err = remote.Dial()
	if err != nil {
		log.Fatalf("err")
	}
	defer remoteKite.Close()

	os.Exit(m.Run())
}
开发者ID:koding,项目名称:koding,代码行数:31,代码来源:methods_test.go

示例5: TestKite_MultipleDial

func TestKite_MultipleDial(t *testing.T) {
	esrv := kite.New("echo-server", "0.0.0")
	esrv.Config.DisableAuthentication = true
	if err := esrv.Config.ReadEnvironmentVariables(); err != nil {
		t.Fatal(err)
	}

	esrv.HandleFunc("echo", func(r *kite.Request) (interface{}, error) {
		var arg string

		if err := r.Args.One().Unmarshal(&arg); err != nil {
			return nil, err
		}

		if arg == "" {
			return nil, errors.New("arg is empty")
		}

		return arg, nil
	})

	ts := httptest.NewServer(esrv)
	ecli := kite.New("echo-client", "0.0.0")
	if err := ecli.Config.ReadEnvironmentVariables(); err != nil {
		t.Fatal(err)
	}

	esrv.SetLogLevel(kite.DEBUG)
	ecli.SetLogLevel(kite.DEBUG)

	c := ecli.NewClient(fmt.Sprintf("%s/kite", ts.URL))

	if err := c.Dial(); err != nil {
		t.Fatalf("dialing echo-server kite error: %s", err)
	}

	if err := c.Dial(); err != nil {
		t.Fatalf("dialing echo-server kite error: %s", err)
	}

	resp, err := c.Tell("echo", "Hello world!")
	if err != nil {
		t.Fatalf("Tell()=%s", err)
	}

	var reply string

	if err := resp.Unmarshal(&reply); err != nil {
		t.Fatalf("Unmarshal()=%s", err)
	}

	if reply != "Hello world!" {
		t.Fatalf(`got %q, want "Hello world!"`, reply)
	}
}
开发者ID:rjeczalik,项目名称:kite,代码行数:55,代码来源:bug_test.go

示例6: TestMain

func TestMain(m *testing.M) {
	flag.Parse()

	// NOTE(rjeczalik): copy testdata/testfile1.txt so after test execution
	// the file is not modified.
	if err := testutil.FileCopy("testdata/testfile1.txt", testfile1); err != nil {
		panic(err)
	}

	kiteURL := testutil.GenKiteURL()

	fs = kite.New("fs", "0.0.1")
	fs.Config.DisableAuthentication = true
	fs.Config.Port = kiteURL.Port()
	fs.HandleFunc("readDirectory", ReadDirectory)
	fs.HandleFunc("glob", Glob)
	fs.HandleFunc("readFile", ReadFile)
	fs.HandleFunc("writeFile", WriteFile)
	fs.HandleFunc("uniquePath", UniquePath)
	fs.HandleFunc("getInfo", GetInfo)
	fs.HandleFunc("setPermissions", SetPermissions)
	fs.HandleFunc("remove", Remove)
	fs.HandleFunc("rename", Rename)
	fs.HandleFunc("createDirectory", CreateDirectory)
	fs.HandleFunc("move", Move)
	fs.HandleFunc("copy", Copy)
	fs.HandleFunc("getDiskInfo", GetDiskInfo)

	go fs.Run()
	<-fs.ServerReadyNotify()
	defer fs.Close()

	remoteKite := kite.New("remote", "0.0.1")
	remoteKite.Config.Username = "remote"
	remote = remoteKite.NewClient(kiteURL.String())
	err := remote.Dial()
	if err != nil {
		log.Fatalf("err")
	}
	defer remoteKite.Close()

	remoteKite2 := kite.New("remote2", "0.0.1")
	remoteKite2.Config.Username = "remote2"
	remote2 = remoteKite2.NewClient(kiteURL.String())
	err = remote2.Dial()
	if err != nil {
		log.Fatalf("err")
	}
	defer remoteKite2.Close()

	os.Exit(m.Run())
}
开发者ID:koding,项目名称:koding,代码行数:52,代码来源:fs_test.go

示例7: TestCheckSizeOfRemotefolder

func TestCheckSizeOfRemotefolder(t *testing.T) {
	type ExecResponse struct {
		Stdout     string `json:"stdout"`
		Stderr     string `json:"stderr"`
		ExitStatus int    `json:"exitStatus"`
	}

	// The response that we're going to return on each exec call
	var (
		expectedPath  string = "/foo"
		requestedPath string
	)

	s := kite.New("s", "0.0.0")
	s.Config.DisableAuthentication = true
	s.HandleFunc("fs.getPathSize", func(r *kite.Request) (interface{}, error) {
		var params struct {
			Path string
		}
		if r.Args.One().Unmarshal(&params) != nil || params.Path == "" {
			return nil, errors.New("{path : [string]}")
		}

		requestedPath = params.Path
		return int64(1200000000), nil
	})
	ts := httptest.NewServer(s)

	c := kite.New("c", "0.0.0").NewClient(fmt.Sprintf("%s/kite", ts.URL))

	res, err := checkSizeOfRemoteFolder(&machine.Machine{Transport: c}, expectedPath)
	if err != nil {
		t.Error(err)
	}

	if expectedPath != requestedPath {
		t.Error("Expected path to be the same as requested. expected:%s, got:%s",
			expectedPath, requestedPath)
	}

	// Should return a string
	warning, ok := res.(string)
	if !ok {
		t.Errorf("checkSizeOfRemote did not return a string. Got '%#v'", res)
	}

	// Should return a warning if the filesize is too big
	if warning == "" {
		t.Errorf("checkSizeOfRemote should have returned a warning. Got an empty string instead.")
	}
}
开发者ID:koding,项目名称:koding,代码行数:51,代码来源:mountfolder_test.go

示例8: NewKiteWrapper

func NewKiteWrapper(cfg *conf.KiteConfig) *Wrapper {
	k := kite.New(cfg.Name, cfg.Version)
	k.Config = config.MustGet()
	k.Config.Port = cfg.Port

	return &Wrapper{k, cfg}
}
开发者ID:spetrunin,项目名称:kite-demo,代码行数:7,代码来源:wrapper.go

示例9: NewServerKite

// NewServerKite creates a server kite for the given server.
func NewServerKite(s *Server, name, version string) (*kite.Kite, error) {
	k := kite.New(name, version)

	if s.opts.Config == nil {
		cfg, err := config.Get()
		if err != nil {
			return nil, err
		}
		s.opts.Config = cfg
	}

	s.opts.Config.KontrolURL = s.opts.kontrolURL()
	s.opts.Config.Transport = config.XHRPolling

	if s.opts.Port != 0 {
		s.opts.Config.Port = s.opts.Port
	}
	if s.opts.Region != "" {
		s.opts.Config.Region = s.opts.Region
	}
	if s.opts.Environment != "" {
		s.opts.Config.Environment = s.opts.Environment
	}
	if s.opts.Test {
		s.opts.Config.DisableAuthentication = true
	}
	if s.opts.Debug {
		k.SetLogLevel(kite.DEBUG)
	}

	k.Log = s.opts.Log
	k.Config = s.opts.Config
	k.ClientFunc = httputil.ClientFunc(s.opts.Debug)

	if fn := s.metricsFunc(); fn != nil {
		k.PreHandleFunc(fn)
	}

	k.HandleFunc("register", s.Register)
	k.HandleFunc("registerServices", s.RegisterServices)
	k.HandleHTTPFunc("/healthCheck", artifact.HealthCheckHandler(name))
	k.HandleHTTPFunc("/version", artifact.VersionHandler())

	// Tunnel helper methods, like ports, stats etc.
	k.HandleHTTPFunc("/-/discover/{service}", s.discoverHandler())

	// Route all the rest requests (match all paths that does not begin with /-/).
	k.HandleHTTP(`/{rest:.?$|[^\/].+|\/[^-].+|\/-[^\/].*}`, s.serverHandler())

	u, err := url.Parse(s.opts.registerURL())
	if err != nil {
		return nil, fmt.Errorf("error parsing registerURL: %s", err)
	}

	if err := k.RegisterForever(u); err != nil {
		return nil, fmt.Errorf("error registering to Kontrol: %s", err)
	}

	return k, nil
}
开发者ID:koding,项目名称:koding,代码行数:61,代码来源:server.go

示例10: New

// New creates a new kontrol instance with the given version and config
// instance. Publickey is used for validating tokens and privateKey is used for
// signing tokens.
//
// Public and private keys are RSA pem blocks that can be generated with the
// following command:
//     openssl genrsa -out testkey.pem 2048
//     openssl rsa -in testkey.pem -pubout > testkey_pub.pem
//
func New(conf *config.Config, version string) *Kontrol {
	k := kite.New("kontrol", version)
	k.Config = conf

	// Listen on 4000 by default
	if k.Config.Port == 0 {
		k.Config.Port = DefaultPort
	}

	kontrol := &Kontrol{
		Kite:        k,
		log:         k.Log,
		clientLocks: NewIdlock(),
		heartbeats:  make(map[string]*time.Timer, 0),
		lastIDs:     make([]string, 0),
		lastPublic:  make([]string, 0),
		lastPrivate: make([]string, 0),
	}

	k.HandleFunc("register", kontrol.handleRegister)
	k.HandleFunc("registerMachine", kontrol.handleMachine).DisableAuthentication()
	k.HandleFunc("getKites", kontrol.handleGetKites)
	k.HandleFunc("getToken", kontrol.handleGetToken)
	k.HandleFunc("getKey", kontrol.handleGetKey)

	k.HandleHTTPFunc("/register", kontrol.handleRegisterHTTP)
	k.HandleHTTPFunc("/heartbeat", kontrol.handleHeartbeat)

	return kontrol
}
开发者ID:gotao,项目名称:kite,代码行数:39,代码来源:kontrol.go

示例11: WaitTillConnected

func WaitTillConnected(conf *Config, timeout time.Duration, hks ...*HelloKite) error {
	k := kite.New("WaitTillConnected", "1.0.0")
	k.Config = conf.Config.Copy()

	t := time.After(timeout)

	for {
		select {
		case <-t:
			return fmt.Errorf("timed out waiting for %v after %s", hks, timeout)
		default:
			kites, err := k.GetKites(&protocol.KontrolQuery{
				Version: "1.0.0",
			})
			if err != nil && err != kite.ErrNoKitesAvailable {
				return err
			}

			notReady := make(map[string]struct{}, len(hks))
			for _, hk := range hks {
				notReady[hk.Kite.Kite().ID] = struct{}{}
			}

			for _, kite := range kites {
				delete(notReady, kite.Kite.ID)
			}

			if len(notReady) == 0 {
				return nil
			}
		}
	}
}
开发者ID:rjeczalik,项目名称:kite,代码行数:33,代码来源:helper_test.go

示例12: main

func main() {
	// Create a kite
	k := kite.New("math", "1.0.0")

	// Add pre handler method
	k.PreHandleFunc(func(r *kite.Request) (interface{}, error) {
		fmt.Println("\nThis pre handler is executed before the method is executed")

		// let us return an hello to base square method!
		return "hello from pre handler!", nil
	})

	// Add post handler method
	k.PostHandleFunc(func(r *kite.Request) (interface{}, error) {
		fmt.Println("This post handler is executed after the method is executed")

		// pass the response from the previous square method back to the
		// client, this is imporant if you use post handler
		return r.Response, nil
	})

	// Add our handler method, authentication is disabled for this example
	k.HandleFunc("square", Square).DisableAuthentication().PreHandleFunc(func(r *kite.Request) (interface{}, error) {
		fmt.Println("This pre handler is only valid for this individual method")
		return nil, nil
	})

	// Attach to a server and run it
	k.Config.Port = 3636
	k.Run()
}
开发者ID:gotao,项目名称:kite,代码行数:31,代码来源:math.go

示例13: New

func New(conf *config.Config, version, pubKey, privKey string) *Proxy {
	k := kite.New("tunnelproxy", version)
	k.Config = conf

	// Listen on 3999 by default
	if k.Config.Port == 0 {
		k.Config.Port = DefaultPort
	}

	p := &Proxy{
		Kite:              k,
		readyC:            make(chan bool),
		closeC:            make(chan bool),
		pubKey:            pubKey,
		privKey:           privKey,
		kites:             make(map[string]*PrivateKite),
		mux:               http.NewServeMux(),
		RegisterToKontrol: true,
		PublicHost:        DefaultPublicHost,
	}

	p.Kite.HandleFunc("register", p.handleRegister)

	p.mux.Handle("/", p.Kite)
	p.mux.Handle("/proxy/", sockjsHandlerWithRequest("/proxy", sockjs.DefaultOptions, p.handleProxy))    // Handler for clients outside
	p.mux.Handle("/tunnel/", sockjsHandlerWithRequest("/tunnel", sockjs.DefaultOptions, p.handleTunnel)) // Handler for kites behind

	// Remove URL from the map when PrivateKite disconnects.
	k.OnDisconnect(func(r *kite.Client) {
		delete(p.kites, r.Kite.ID)
	})

	return p
}
开发者ID:GregWilson,项目名称:kite,代码行数:34,代码来源:proxy.go

示例14: NewWithoutHandlers

// NewWithoutHandlers creates a new kontrol instance with the given version and config
// instance, but *without* the default handlers. If this is function is
// used, make sure to implement the expected kontrol functionality.
//
// Example:
//
//     kontrol := NewWithoutHandlers(conf, version)
//     kontrol.Kite.HandleFunc("register", kontrol.HandleRegister)
//     kontrol.Kite.HandleFunc("registerMachine", kontrol.HandleMachine).DisableAuthentication()
//     kontrol.Kite.HandleFunc("getKites", kontrol.HandleGetKites)
//     kontrol.Kite.HandleFunc("getToken", kontrol.HandleGetToken)
//     kontrol.Kite.HandleFunc("getKey", kontrol.HandleGetKey)
//     kontrol.Kite.HandleHTTPFunc("/heartbeat", kontrol.HandleHeartbeat)
//     kontrol.Kite.HandleHTTPFunc("/register", kontrol.HandleRegisterHTTP)
//
func NewWithoutHandlers(conf *config.Config, version string) *Kontrol {
	k := &Kontrol{
		clientLocks: NewIdlock(),
		heartbeats:  make(map[string]*heartbeat),
		closed:      make(chan struct{}),
		tokenCache:  make(map[string]string),
	}

	// Make a copy to not modify user-provided value.
	conf = conf.Copy()

	// Listen on 4000 by default.
	if conf.Port == 0 {
		conf.Port = DefaultPort
	}

	// Allow keys that were recently deleted - for Register{,HTTP} to
	// give client kite a chance to update them.
	if conf.VerifyFunc == nil {
		conf.VerifyFunc = k.Verify
	}

	k.Kite = kite.New("kontrol", version)
	k.Kite.Config = conf
	k.log = k.Kite.Log

	return k
}
开发者ID:rjeczalik,项目名称:kite,代码行数:43,代码来源:kontrol.go

示例15: main

func main() {
	// Create a kite
	k := kite.New("exp2", "1.0.0")
	k.Config = config.MustGet()

	onEvent := func(e *kite.Event, err *kite.Error) {
		fmt.Printf("e %+v\n", e)
		fmt.Printf("err %+v\n", err)
	}

	_, err := k.WatchKites(protocol.KontrolQuery{
		Username:    k.Config.Username,
		Environment: k.Config.Environment,
		Name:        "math",
		// ID: "48bb002b-79f6-4a4e-6bba-a40567a08b6c",
	}, onEvent)
	if err != nil {
		log.Fatalln(err)
	}

	// This is a bad example, it's just for testing the watch functionality :)
	fmt.Println("listening to events")

	select {}
}
开发者ID:GregWilson,项目名称:kite,代码行数:25,代码来源:exp2-watch.go


注:本文中的github.com/koding/kite.New函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。