Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add registered clients feature #86

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

moisespsena
Copy link

Add registered clients feature. See README.md for more details.

@mmatczuk
Copy link
Owner

Hi @moisespsena,
could you please elaborate on what this patch set does what is the motivation.
Overall it's a massive PR, I do not follow all the decisions such as moving cmd to cli could you give more insight to that too.

@moisespsena
Copy link
Author

moisespsena commented Oct 17, 2018

Hi @mmatczuk,

  1. My motivation was a need to have multiple data collectors behind a router and that could be accessed externally. As these collectors are sent to various places on different projects, and because they have no control over these collectors, the need arose to release the tunnel only to registered collectors.

  2. I moved cmd to cli to allow exposes "tunnel" and "tunneld" to be embedded.

Example for embed tunnel in your code.

package main

import "github.com/mmatczuk/go-http-tunnel/cli/tunnel"

func tunnelClient() {
	options, err := tunnel.ParseArgs(false, "mycmd", "start-all")
	if err != nil {
		panic(err)
	}
	tunnel.MainConfigOptions(&tunnel.ClientConfig{
		ServerAddr: "domain.com:2000",
		Tunnels: map[string]*tunnel.Tunnel{
			"main": {
				Protocol:   "tcp",
				LocalAddr:  "localhost:5000",
				RemoteAddr: "domain.com:5000",
			},
		},
	}, options)
}

func main() {
	go tunnelClient()

	// ... my system code
}

Example for embed tunneld in your code.

package main

import "github.com/mmatczuk/go-http-tunnel/cli/tunneld"

func main() {
	go tunneld.MainArgs("mycmd", "-log-level", "3", "-httpAddr", ":19000", "-httpsAddr", ":19001")

	// ... my system code
}

@@ -21,6 +22,7 @@ const (
DefaultBackoffMultiplier = 1.5
DefaultBackoffMaxInterval = 60 * time.Second
DefaultBackoffMaxTime = 15 * time.Minute
ConfigFileSTDIN = "-"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like it's not part of "Default backoff configuration."

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only stdin file path reference.

@@ -24,7 +24,7 @@ import (
)

func Main() {
MainArgs(os.Args[1:]...)
MainArgs(os.Args...)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the old version, the ParseArgs function uses the os.Args[0], for command name, now, uses the first passed argument.

@@ -91,7 +91,8 @@ func ParseArgs(hasConfig bool, args ...string) (*options, error) {
cli := flag.NewFlagSet(args[0], flag.ExitOnError)
args = args[1:]
if hasConfig {
config = cli.String("config", "tunnel.yaml", "Path to tunnel configuration file")
config = cli.String("config", "tunnel.yaml",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about Path to tunnel configuration file, for reading from STDIN use '-'.?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used as an example the "cat" command: cat -

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants