func NewV2()

in pkg/client/client_v2.go [291:320]


func NewV2(target string, token string, versionInfo VersionInfo, opts ...V2ClientOption) V2 {
	var options v2options
	options.maxMessageSize = DefaultMaxMessageSize
	for _, o := range opts {
		o(&options)
	}

	// For compatibility with existing interface the target could contain npipe:// scheme prefix
	// Set the named pipe dialer option if npipe:// prefix specified on windows
	if runtime.GOOS == "windows" && npipe.IsNPipe(target) {
		target = transformNPipeURL(target)
		// Set the winio named pipe dialer
		options.dialOptions = append(options.dialOptions, getOptions()...)
	}

	c := &clientV2{
		agentInfo:             options.agentInfo,
		target:                target,
		opts:                  options,
		token:                 token,
		versionInfo:           versionInfo,
		stateChangeObservedCh: make(chan struct{}, 1),
		errCh:                 make(chan error),
		changesCh:             make(chan UnitChanged),
		diagHooks:             make(map[string]diagHook),
		minCheckTimeout:       CheckinMinimumTimeout,
	}
	c.registerDefaultDiagnostics()
	return c
}