本文整理汇总了Golang中github.com/koding/kite.Client类的典型用法代码示例。如果您正苦于以下问题:Golang Client类的具体用法?Golang Client怎么用?Golang Client使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Client类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: Stop
func (c *Client) Stop(id string, remote *kite.Client) error {
stopArgs := &args{
MachineId: id,
Provider: c.Provider,
}
resp, err := remote.Tell("stop", stopArgs)
if err != nil {
return err
}
var result kloud.ControlResult
err = resp.Unmarshal(&result)
if err != nil {
return err
}
eArgs := kloud.EventArgs([]kloud.EventArg{
{
EventId: stopArgs.MachineId,
Type: "stop",
},
})
return listenEvent(eArgs, machinestate.Stopped, remote)
}
开发者ID:koding,项目名称:koding,代码行数:26,代码来源:main_test.go
示例2: CreateSnapshot
func (c *Client) CreateSnapshot(id string, remote *kite.Client) error {
createSnapshotArgs := &args{
MachineId: id,
Provider: c.Provider,
}
resp, err := remote.Tell("createSnapshot", createSnapshotArgs)
if err != nil {
return err
}
var result kloud.ControlResult
err = resp.Unmarshal(&result)
if err != nil {
return err
}
eArgs := kloud.EventArgs([]kloud.EventArg{
{
EventId: createSnapshotArgs.MachineId,
Type: "createSnapshot",
},
})
return listenEvent(eArgs, machinestate.Running, remote)
}
开发者ID:koding,项目名称:koding,代码行数:26,代码来源:main_test.go
示例3: checkTunnel
func (s *Stack) checkTunnel(c *kite.Client) error {
resp, err := c.TellWithTimeout("tunnel.info", 2*time.Minute)
if err != nil {
return err
}
var info tunnel.InfoResponse
if err := resp.Unmarshal(&info); err != nil {
return err
}
s.Log.Debug("received tunnel.info response: %+v", &info)
if info.State != tunnel.StateConnected {
// We do not fail here, as the tunnel can be recovering
// and we might hit the window when it's not yet done.
// However we log, to show kloud observed problems with
// connection.
s.Log.Warning("%s: want tunnel to be %q, was %q instead", c.ID, tunnel.StateConnected, info.State)
return nil
}
if _, ok := info.Ports["kite"]; !ok {
// Every klient has its connection to kontrol tunneled, thus
// tunnel.info should report ports for kite. Warn if there're
// none to show kloud observed unexpected behavior.
// However it is not critical though, as we were able to
// kite.ping the klient, it means the klient may have some
// other problems (connection with host kite etc.).
s.Log.Warning("%s: no ports for kite", c.ID)
}
return nil
}
开发者ID:koding,项目名称:koding,代码行数:35,代码来源:stack.go
示例4: TodosHandler
func TodosHandler(app *kite.Client, w http.ResponseWriter, r *http.Request) {
token := r.Header.Get("token")
result, err := app.Tell("todos", token)
if err != nil {
fmt.Println("Failed to get todos", err)
w.WriteHeader(http.StatusUnauthorized)
return
}
w.Write(result.Raw)
}
开发者ID:spetrunin,项目名称:kite-demo,代码行数:12,代码来源:todoshandler.go
示例5: configureKiteClient
// configureKiteClient
func configureKiteClient(c *kite.Client) error {
// Set reconnect.
// https://github.com/koding/kite/blob/master/client.go#L300
c.Reconnect = true
return nil
}
开发者ID:koding,项目名称:koding,代码行数:8,代码来源:remote.go
示例6: watch
// watch watches the events of the specified event type.
func watch(k *kite.Client, eventType string, eventId string, interval time.Duration) error {
eventArgs := stack.EventArgs([]stack.EventArg{
{
Type: eventType,
EventId: eventId,
},
})
for {
resp, err := k.TellWithTimeout("event", defaultTellTimeout, eventArgs)
if err != nil {
return err
}
var events []stack.EventResponse
if err := resp.Unmarshal(&events); err != nil {
return err
}
if len(events) == 0 {
return errors.New("incoming event response is not an array")
}
if events[0].Error != nil {
return events[0].Error
}
DefaultUi.Info(fmt.Sprintf("%s ==> %s [Status: %s Percentage: %d]",
fmt.Sprint(time.Now())[:19],
events[0].Event.Message,
events[0].Event.Status,
events[0].Event.Percentage,
))
if events[0].Event.Error != "" {
err := errors.New(events[0].Event.Error)
DefaultUi.Error(err.Error())
return err
}
if events[0].Event.Percentage == 100 {
return nil
}
time.Sleep(interval)
}
}
开发者ID:koding,项目名称:koding,代码行数:48,代码来源:event.go
示例7: SingleMachine
func (c *Cmd) SingleMachine(id string, k *kite.Client) (string, error) {
resp, err := k.Tell(c.command, &KloudArgs{
MachineId: id,
Provider: *c.provider,
})
if err != nil {
return "", err
}
var result stack.ControlResult
err = resp.Unmarshal(&result)
if err != nil {
return "", err
}
return result.EventId, nil
}
开发者ID:koding,项目名称:koding,代码行数:17,代码来源:cmd.go
示例8: SingleMachine
func (i *Info) SingleMachine(id string, k *kite.Client) (string, error) {
infoArgs := &KloudArgs{
MachineId: id,
Provider: *i.provider,
}
resp, err := k.Tell("info", infoArgs)
if err != nil {
return "", err
}
var result stack.InfoResponse
err = resp.Unmarshal(&result)
if err != nil {
return "", err
}
return result.State.String(), nil
}
开发者ID:koding,项目名称:koding,代码行数:19,代码来源:info.go
示例9: LoginHandler
func LoginHandler(auth *kite.Client, w http.ResponseWriter, r *http.Request) {
params := map[string]string{
"user": r.FormValue("username"),
"pass": r.FormValue("password"),
}
result, err := auth.Tell("login", params)
if err != nil {
fmt.Println("Failed to login:", err)
w.WriteHeader(http.StatusUnauthorized)
return
}
token, _ := result.String()
json, _ := json.Marshal(map[string]string{"token": token})
w.Write(json)
}
开发者ID:spetrunin,项目名称:kite-demo,代码行数:19,代码来源:loginhandler.go
示例10: Build
func (c *Client) Build(id string, remote *kite.Client) error {
buildArgs := &args{
MachineId: id,
Provider: c.Provider,
TerraformContext: fmt.Sprintf(`
provider "aws" {
access_key = "${var.aws_access_key}"
secret_key = "${var.aws_secret_key}"
region = "%s"
}
resource "aws_instance" "example" {
ami = "ami-d05e75b8"
instance_type = "%s"
}`, c.region(), c.instanceType()),
}
resp, err := remote.Tell("build", buildArgs)
if err != nil {
return err
}
var result kloud.ControlResult
err = resp.Unmarshal(&result)
if err != nil {
return err
}
eArgs := kloud.EventArgs([]kloud.EventArg{
{
EventId: buildArgs.MachineId,
Type: "build",
},
})
return listenEvent(eArgs, machinestate.Running, remote)
}
开发者ID:koding,项目名称:koding,代码行数:38,代码来源:main_test.go
示例11: listenEvent
// listenEvent calls the event method of kloud with the given arguments until
// the desiredState is received. It times out if the desired state is not
// reached in 10 miunuts.
func listenEvent(args kloud.EventArgs, desiredState machinestate.State, remote *kite.Client) error {
tryUntil := time.Now().Add(time.Minute * 10)
for {
resp, err := remote.Tell("event", args)
if err != nil {
return err
}
var events []kloud.EventResponse
if err := resp.Unmarshal(&events); err != nil {
return err
}
e := events[0]
if e.Error != nil {
return e.Error
}
// fmt.Printf("e = %+v\n", e)
event := e.Event
if event.Error != "" {
return fmt.Errorf("%s: %s", args[0].Type, event.Error)
}
if event.Status == desiredState {
return nil
}
if time.Now().After(tryUntil) {
return fmt.Errorf("Timeout while waiting for state %s", desiredState)
}
time.Sleep(2 * time.Second)
continue // still pending
}
}
开发者ID:koding,项目名称:koding,代码行数:40,代码来源:main_test.go
示例12: main
func main() {
authorizer := auth.NewAuthorizer()
authConfig, err := conf.NewConfig("auth")
if err != nil {
fmt.Println("Error getting config", err)
return
}
k := kitewrapper.NewKiteWrapper(authConfig)
err = k.RegisterToKontrol()
if err != nil {
fmt.Println("Failed to register", err)
return
}
var dbKite *kite.Client
go func() {
var err error
dbKite, err = k.FindAndDial("db_accessor")
if err != nil {
fmt.Println("Failed to dial db service", err)
// return
}
}()
// Add our handler method
k.HandleFunc("login", func(r *kite.Request) (interface{}, error) {
var (
params, _ = r.Args.One().Map()
user, _ = params["user"].String()
pass, _ = params["pass"].String()
)
if user == User && pass == Pass {
return authorizer.Token, nil
}
return nil, BadCredentials
})
k.HandleFunc("profile", func(r *kite.Request) (interface{}, error) {
token, err := r.Args.One().String()
if err != nil {
return nil, BadCredentials
}
if !authorizer.Validate(token) {
return nil, BadCredentials
}
result, err := dbKite.Tell("query", "profile")
if err != nil {
return nil, err
}
var (
profileMap, _ = result.Map()
profile = make(map[string]string)
)
for name, value := range profileMap {
val, _ := value.String()
profile[name] = val
}
return profile, nil
})
k.HandleFunc("validateToken", func(r *kite.Request) (interface{}, error) {
token, err := r.Args.One().String()
if err != nil {
return false, BadCredentials
}
return authorizer.Validate(token), nil
})
k.Run()
}
开发者ID:spetrunin,项目名称:kite-demo,代码行数:82,代码来源:authkite.go
注:本文中的github.com/koding/kite.Client类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论