ports

package
v0.30.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 11, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var PortForwardCmd = &cobra.Command{
	Use:     "forward [PORT] [WORKSPACE] [PROJECT]",
	Short:   "Forward a port from a project to your local machine",
	GroupID: util.WORKSPACE_GROUP,
	Args:    cobra.RangeArgs(2, 3),
	Run: func(cmd *cobra.Command, args []string) {
		c, err := config.GetConfig()
		if err != nil {
			log.Fatal(err)
		}
		activeProfile, err := c.GetActiveProfile()
		if err != nil {
			log.Fatal(err)
		}

		port, err := strconv.Atoi(args[0])
		if err != nil {
			log.Fatal(err)
		}
		workspace, err := apiclient.GetWorkspace(args[1], true)
		if err != nil {
			log.Fatal(err)
		}
		workspaceId = workspace.Id

		if len(args) == 3 {
			projectName = args[2]
		} else {
			projectName, err = apiclient.GetFirstWorkspaceProjectName(workspaceId, projectName, nil)
			if err != nil {
				log.Fatal(err)
			}
		}

		hostPort, errChan := tailscale.ForwardPort(workspaceId, projectName, uint16(port), activeProfile)

		if hostPort == nil {
			if err = <-errChan; err != nil {
				log.Fatal(err)
			}
		} else {
			if *hostPort != uint16(port) {
				views.RenderInfoMessage(fmt.Sprintf("Port %d already in use.", port))
			}
			views.RenderInfoMessage(fmt.Sprintf("Port available at http://localhost:%d\n", *hostPort))
		}

		if publicPreview {
			go func() {
				errChan <- ForwardPublicPort(workspaceId, projectName, *hostPort, uint16(port))
			}()
		}

		for {
			err := <-errChan
			if err != nil {
				log.Debug(err)
			}
		}
	},
}

Functions

func ForwardPublicPort added in v0.15.0

func ForwardPublicPort(workspaceId, projectName string, hostPort, targetPort uint16) error

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL