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


Golang GsiClient.Do方法代码示例

本文整理汇总了Golang中github.com/couchbase/indexing/secondary/queryport/client.GsiClient.Do方法的典型用法代码示例。如果您正苦于以下问题:Golang GsiClient.Do方法的具体用法?Golang GsiClient.Do怎么用?Golang GsiClient.Do使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/couchbase/indexing/secondary/queryport/client.GsiClient的用法示例。


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

示例1: HandleCommand


//.........这里部分代码省略.........
		index, _ := GetIndex(client, bucket, iname)
		defnID := uint64(index.Definition.DefnId)
		_, err = WaitUntilIndexState(
			client, []uint64{defnID}, c.INDEX_STATE_ACTIVE,
			100 /*period*/, 20000 /*timeout*/)
		if err != nil {
			state, err = client.IndexState(defnID)
			fmt.Fprintf(w, "Index state: {%v, %v} \n", state, err)
		} else if cmd.Equal != nil {
			fmt.Fprintln(w, "CountLookup:")
			equals := []c.SecondaryKey{cmd.Equal}
			count, err := client.CountLookup(uint64(defnID), equals, cons, nil)
			if err == nil {
				fmt.Fprintf(w, "Index %q/%q has %v entries\n", bucket, iname, count)
			}

		} else {
			fmt.Fprintln(w, "CountRange:")
			count, err = client.CountRange(uint64(defnID), low, high, incl, cons, nil)
			if err == nil {
				fmt.Fprintf(w, "Index %q/%q has %v entries\n", bucket, iname, count)
			}
		}

	case "config":
		nodes, err := client.Nodes()
		if err != nil {
			return err
		}
		var adminurl string
		for _, indexer := range nodes {
			adminurl = indexer.Adminport
			break
		}
		host, sport, _ := net.SplitHostPort(adminurl)
		iport, _ := strconv.Atoi(sport)
		client := http.Client{}

		//
		// hack, fix this
		//
		ihttp := iport + 2
		url := "http://" + host + ":" + strconv.Itoa(ihttp) + "/settings"

		oreq, err := http.NewRequest("GET", url, nil)
		if cmd.Auth != "" {
			up := strings.Split(cmd.Auth, ":")
			oreq.SetBasicAuth(up[0], up[1])
		}

		oresp, err := client.Do(oreq)
		if err != nil {
			return err
		}
		obody, err := ioutil.ReadAll(oresp.Body)
		if err != nil {
			return err
		}
		oresp.Body.Close()

		pretty := strings.Replace(string(obody), ",\"", ",\n\"", -1)
		fmt.Printf("Current Settings:\n%s\n", string(pretty))

		var jbody map[string]interface{}
		err = json.Unmarshal(obody, &jbody)
		if err != nil {
			return err
		}

		if len(cmd.ConfigKey) > 0 {
			fmt.Printf("Changing config key '%s' to value '%s'\n", cmd.ConfigKey, cmd.ConfigVal)
			jbody[cmd.ConfigKey] = cmd.ConfigVal

			pbody, err := json.Marshal(jbody)
			if err != nil {
				return err
			}
			preq, err := http.NewRequest("POST", url, bytes.NewBuffer(pbody))
			if cmd.Auth != "" {
				up := strings.Split(cmd.Auth, ":")
				preq.SetBasicAuth(up[0], up[1])
			}
			_, err = client.Do(preq)
			if err != nil {
				return err
			}
			nresp, err := client.Do(oreq)
			if err != nil {
				return err
			}
			nbody, err := ioutil.ReadAll(nresp.Body)
			if err != nil {
				return err
			}
			pretty = strings.Replace(string(nbody), ",\"", ",\n\"", -1)
			fmt.Printf("New Settings:\n%s\n", string(pretty))
		}
	}
	return err
}
开发者ID:jchris,项目名称:indexing,代码行数:101,代码来源:docmd.go


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