• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang client.ParseConnectionString函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: TestClient_ParseConnectionString_IPv6

func TestClient_ParseConnectionString_IPv6(t *testing.T) {
	path := "[fdf5:9ede:1875:0:a9ee:a600:8fe3:d495]:8086"
	u, err := client.ParseConnectionString(path, false)
	if err != nil {
		t.Fatalf("unexpected error, expected %v, actual %v", nil, err)
	}
	if u.Host != path {
		t.Fatalf("ipv6 parse failed, expected %s, actual %s", path, u.Host)
	}
}
开发者ID:seiflotfy,项目名称:influxdb,代码行数:10,代码来源:influxdb_test.go


示例2: NewInfluxHandler

// InfluxHandler factory function
// reutrn *InfluxHandler and error
func NewInfluxHandler(h string, p int, db string, u string, pwd string, max int, delay int) (*InfluxHandler, error) {
	url, err := client.ParseConnectionString(fmt.Sprintf("%s:%d", h, p), false)
	if err != nil {
		return nil, err
	}

	cfg := client.NewConfig()
	cfg.URL = url
	cfg.Username = u
	cfg.Password = pwd
	cfg.Precision = "s" // 秒级别的精度就行

	c, e := client.NewClient(cfg)
	if e != nil {
		return nil, e
	}

	_, _, err = c.Ping()
	if err != nil {
		return nil, err
	}

	ih := new(InfluxHandler)
	ih.c = c
	ih.force = make(chan struct{}, 1)
	ih.last = time.Now()
	ih.h = h
	ih.p = p
	ih.db = db
	ih.u = u
	ih.pwd = pwd

	if max <= 10 || max > 4096 {
		ih.max = 4096
	} else {
		ih.max = max
	}

	if delay <= 60 || delay > 600 {
		ih.delay = time.Second * 600
	} else {
		ih.delay = time.Second * delay
	}

	ih.ch = make(chan unit, int(ih.max+ih.max/2))

	go ih.consume()

	return ih, nil
}
开发者ID:dongzerun,项目名称:influxwrap,代码行数:52,代码来源:influxdb.go


示例3: Connect

// Connect connects client to a server
func (c *CommandLine) Connect(cmd string) error {
	var cl *client.Client
	var u url.URL

	// Remove the "connect" keyword if it exists
	path := strings.TrimSpace(strings.Replace(cmd, "connect", "", -1))

	// If they didn't provide a connection string, use the current settings
	if path == "" {
		path = net.JoinHostPort(c.Host, strconv.Itoa(c.Port))
	}

	var e error
	u, e = client.ParseConnectionString(path, c.Ssl)
	if e != nil {
		return e
	}

	config := client.NewConfig()
	config.URL = u
	config.UnixSocket = c.UnixSocket
	config.Username = c.Username
	config.Password = c.Password
	config.UserAgent = "InfluxDBShell/" + c.ClientVersion
	config.Precision = c.Precision
	config.UnsafeSsl = c.UnsafeSsl
	cl, err := client.NewClient(config)
	if err != nil {
		return fmt.Errorf("Could not create client %s", err)
	}
	c.Client = cl

	var v string
	if _, v, e = c.Client.Ping(); e != nil {
		return fmt.Errorf("Failed to connect to %s: %s\n", c.Client.Addr(), e.Error())
	}
	c.ServerVersion = v
	// Update the command with the current connection information
	if h, p, err := net.SplitHostPort(config.URL.Host); err == nil {
		c.Host = h
		if i, err := strconv.Atoi(p); err == nil {
			c.Port = i
		}
	}

	return nil
}
开发者ID:luizbafilho,项目名称:fusis,代码行数:48,代码来源:cli.go


示例4: Connect

// Connect connects client to a server
func (c *CommandLine) Connect(cmd string) error {
	// Remove the "connect" keyword if it exists
	addr := strings.TrimSpace(strings.Replace(cmd, "connect", "", -1))
	if addr == "" {
		// If they didn't provide a connection string, use the current settings
		addr = net.JoinHostPort(c.Host, strconv.Itoa(c.Port))
	}

	URL, err := client.ParseConnectionString(addr, c.Ssl)
	if err != nil {
		return err
	}

	// Create copy of the current client config and create a new client.
	ClientConfig := c.ClientConfig
	ClientConfig.UserAgent = "InfluxDBShell/" + c.ClientVersion
	ClientConfig.URL = URL

	client, err := client.NewClient(ClientConfig)
	if err != nil {
		return fmt.Errorf("Could not create client %s", err)
	}
	c.Client = client

	_, v, err := c.Client.Ping()
	if err != nil {
		return fmt.Errorf("Failed to connect to %s: %v\n", c.Client.Addr(), err)
	}
	c.ServerVersion = v

	// Update the command with the current connection information
	if host, port, err := net.SplitHostPort(ClientConfig.URL.Host); err == nil {
		c.Host = host
		if i, err := strconv.Atoi(port); err == nil {
			c.Port = i
		}
	}

	return nil
}
开发者ID:li-ang,项目名称:influxdb,代码行数:41,代码来源:cli.go


示例5: Run

// Run executes the CLI
func (c *CommandLine) Run() error {
	if !c.IgnoreSignals {
		// register OS signals for graceful termination
		signal.Notify(c.osSignals, syscall.SIGINT, syscall.SIGTERM)
	}

	var promptForPassword bool
	// determine if they set the password flag but provided no value
	for _, v := range os.Args {
		v = strings.ToLower(v)
		if (strings.HasPrefix(v, "-password") || strings.HasPrefix(v, "--password")) && c.Password == "" {
			promptForPassword = true
			break
		}
	}

	c.Line = liner.NewLiner()
	defer c.Line.Close()

	c.Line.SetMultiLineMode(true)

	if promptForPassword {
		p, e := c.Line.PasswordPrompt("password: ")
		if e != nil {
			fmt.Println("Unable to parse password.")
		} else {
			c.Password = p
		}
	}

	if err := c.Connect(""); err != nil {
		return fmt.Errorf(
			"Failed to connect to %s\nPlease check your connection settings and ensure 'influxd' is running.",
			c.Client.Addr())
	}

	// Modify precision.
	c.SetPrecision(c.Precision)

	if c.Execute == "" && !c.Import {
		token, err := c.DatabaseToken()
		if err != nil {
			return fmt.Errorf("Failed to check token: %s", err.Error())
		}
		if token == "" {
			fmt.Printf(noTokenMsg)
		}
		fmt.Printf("Connected to %s version %s\n", c.Client.Addr(), c.ServerVersion)
	}

	if c.Execute != "" {
		// Make the non-interactive mode send everything through the CLI's parser
		// the same way the interactive mode works
		lines := strings.Split(c.Execute, "\n")
		for _, line := range lines {
			if err := c.ParseCommand(line); err != nil {
				return err
			}
		}

		c.Line.Close()
		return nil
	}

	if c.Import {
		path := net.JoinHostPort(c.Host, strconv.Itoa(c.Port))
		u, e := client.ParseConnectionString(path, c.Ssl)
		if e != nil {
			return e
		}

		config := v8.NewConfig()
		config.Username = c.Username
		config.Password = c.Password
		config.Precision = "ns"
		config.WriteConsistency = "any"
		config.Path = c.Path
		config.Version = c.ClientVersion
		config.URL = u
		config.Compressed = c.Compressed
		config.PPS = c.PPS
		config.Precision = c.Precision

		i := v8.NewImporter(config)
		if err := i.Import(); err != nil {
			err = fmt.Errorf("ERROR: %s\n", err)
			c.Line.Close()
			return err
		}
		c.Line.Close()
		return nil
	}

	c.Version()

	// Only load/write history if HOME environment variable is set.
	if homeDir := os.Getenv("HOME"); homeDir != "" {
		// Attempt to load the history file.
		c.historyFilePath = filepath.Join(homeDir, ".influx_history")
//.........这里部分代码省略.........
开发者ID:jsternberg,项目名称:influxdb,代码行数:101,代码来源:cli.go


示例6: Run

// Run executes the CLI
func (c *CommandLine) Run() error {
	// register OS signals for graceful termination
	if !c.IgnoreSignals {
		signal.Notify(c.osSignals, os.Kill, os.Interrupt, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGHUP)
	}

	var promptForPassword bool
	// determine if they set the password flag but provided no value
	for _, v := range os.Args {
		v = strings.ToLower(v)
		if (strings.HasPrefix(v, "-password") || strings.HasPrefix(v, "--password")) && c.Password == "" {
			promptForPassword = true
			break
		}
	}

	c.Line = liner.NewLiner()
	defer c.Line.Close()

	c.Line.SetMultiLineMode(true)

	if promptForPassword {
		p, e := c.Line.PasswordPrompt("password: ")
		if e != nil {
			fmt.Println("Unable to parse password.")
		} else {
			c.Password = p
		}
	}

	if err := c.Connect(""); err != nil {
		return fmt.Errorf(
			"Failed to connect to %s\nPlease check your connection settings and ensure 'influxd' is running.",
			c.Client.Addr())
	}

	// Modify precision.
	c.SetPrecision(c.Precision)

	if c.Execute == "" && !c.Import {
		token, err := c.DatabaseToken()
		if err != nil {
			return fmt.Errorf("Failed to check token: %s", err.Error())
		}
		if token == "" {
			fmt.Printf(noTokenMsg)
		}
		fmt.Printf("Connected to %s version %s\n", c.Client.Addr(), c.ServerVersion)
	}

	if c.Execute != "" {
		// Make the non-interactive mode send everything through the CLI's parser
		// the same way the interactive mode works
		lines := strings.Split(c.Execute, "\n")
		for _, line := range lines {
			if err := c.ParseCommand(line); err != nil {
				return err
			}
		}

		c.Line.Close()
		return nil
	}

	if c.Import {
		path := net.JoinHostPort(c.Host, strconv.Itoa(c.Port))
		u, e := client.ParseConnectionString(path, c.Ssl)
		if e != nil {
			return e
		}

		config := v8.NewConfig()
		config.Username = c.Username
		config.Password = c.Password
		config.Precision = "ns"
		config.WriteConsistency = "any"
		config.Path = c.Path
		config.Version = c.ClientVersion
		config.URL = u
		config.Compressed = c.Compressed
		config.PPS = c.PPS
		config.Precision = c.Precision

		i := v8.NewImporter(config)
		if err := i.Import(); err != nil {
			err = fmt.Errorf("ERROR: %s\n", err)
			c.Line.Close()
			return err
		}
		c.Line.Close()
		return nil
	}

	c.Version()

	usr, err := user.Current()
	// Only load/write history if we can get the user
	if err == nil {
		c.historyFilePath = filepath.Join(usr.HomeDir, ".influx_history")
//.........这里部分代码省略.........
开发者ID:carosio,项目名称:influxdb-dist,代码行数:101,代码来源:cli.go


示例7: Run

// Run executes the CLI
func (c *CommandLine) Run() error {
	hasTTY := c.ForceTTY || terminal.IsTerminal(int(os.Stdin.Fd()))

	var promptForPassword bool
	// determine if they set the password flag but provided no value
	for _, v := range os.Args {
		v = strings.ToLower(v)
		if (strings.HasPrefix(v, "-password") || strings.HasPrefix(v, "--password")) && c.Password == "" {
			promptForPassword = true
			break
		}
	}

	// Check if we will be able to prompt for the password later.
	if promptForPassword && !hasTTY {
		return errors.New("Unable to prompt for a password with no TTY.")
	}

	// Read environment variables for username/password.
	if c.Username == "" {
		c.Username = os.Getenv("INFLUX_USERNAME")
	}
	// If we are going to be prompted for a password, always use the entered password.
	if promptForPassword {
		// Open the liner (temporarily) and prompt for the password.
		p, e := func() (string, error) {
			l := liner.NewLiner()
			defer l.Close()
			return l.PasswordPrompt("password: ")
		}()
		if e != nil {
			return errors.New("Unable to parse password")
		}
		c.Password = p
	} else if c.Password == "" {
		c.Password = os.Getenv("INFLUX_PASSWORD")
	}

	if err := c.Connect(""); err != nil {
		return fmt.Errorf(
			"Failed to connect to %s: %s\nPlease check your connection settings and ensure 'influxd' is running.",
			c.Client.Addr(), err.Error())
	}

	// Modify precision.
	c.SetPrecision(c.Precision)

	if c.Execute != "" {
		// Make the non-interactive mode send everything through the CLI's parser
		// the same way the interactive mode works
		lines := strings.Split(c.Execute, "\n")
		for _, line := range lines {
			if err := c.ParseCommand(line); err != nil {
				return err
			}
		}
		return nil
	}

	if c.Import {
		path := net.JoinHostPort(c.Host, strconv.Itoa(c.Port))
		u, e := client.ParseConnectionString(path, c.Ssl)
		if e != nil {
			return e
		}

		config := v8.NewConfig()
		config.Username = c.Username
		config.Password = c.Password
		config.Precision = "ns"
		config.WriteConsistency = "any"
		config.Path = c.Path
		config.Version = c.ClientVersion
		config.URL = u
		config.Compressed = c.Compressed
		config.PPS = c.PPS
		config.Precision = c.Precision

		i := v8.NewImporter(config)
		if err := i.Import(); err != nil {
			err = fmt.Errorf("ERROR: %s\n", err)
			return err
		}
		return nil
	}

	if !hasTTY {
		cmd, err := ioutil.ReadAll(os.Stdin)
		if err != nil {
			return err
		}
		return c.ExecuteQuery(string(cmd))
	}

	if !c.IgnoreSignals {
		// register OS signals for graceful termination
		signal.Notify(c.osSignals, syscall.SIGINT, syscall.SIGTERM)
	}

//.........这里部分代码省略.........
开发者ID:luizbafilho,项目名称:fusis,代码行数:101,代码来源:cli.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang v2.NewBatchPoints函数代码示例发布时间:2022-05-28
下一篇:
Golang client.NewConfig函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap