MCPcopy Index your code
hub / github.com/coder/coder / Server

Method Server

cli/server.go:371–1485  ·  view source on GitHub ↗

nolint:gocognit // TODO(dannyk): reduce complexity of this function

(newAPI func(context.Context, *coderd.Options) (*coderd.API, io.Closer, error))

Source from the content-addressed store, hash-verified

369
370//nolint:gocognit // TODO(dannyk): reduce complexity of this function
371func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd.API, io.Closer, error)) *serpent.Command {
372 if newAPI == nil {
373 newAPI = func(_ context.Context, o *coderd.Options) (*coderd.API, io.Closer, error) {
374 api := coderd.New(o)
375 return api, api, nil
376 }
377 }
378
379 var (
380 vals = new(codersdk.DeploymentValues)
381 opts = vals.Options()
382 )
383 serverCmd := &serpent.Command{
384 Use: "server",
385 Short: "Start a Coder server",
386 Options: opts,
387 Middleware: serpent.Chain(
388 WriteConfigMW(vals),
389 serpent.RequireNArgs(0),
390 ),
391 Handler: func(inv *serpent.Invocation) error {
392 // Main command context for managing cancellation of running
393 // services.
394 ctx, cancel := context.WithCancel(inv.Context())
395 defer cancel()
396
397 if vals.Config != "" {
398 cliui.Warnf(inv.Stderr, "YAML support is experimental and offers no compatibility guarantees.")
399 }
400
401 go DumpHandler(ctx, "coderd")
402
403 // Validate bind addresses.
404 if vals.Address.String() != "" {
405 if vals.TLS.Enable {
406 vals.HTTPAddress = ""
407 vals.TLS.Address = vals.Address
408 } else {
409 _ = vals.HTTPAddress.Set(vals.Address.String())
410 vals.TLS.Address.Host = ""
411 vals.TLS.Address.Port = ""
412 }
413 }
414 if vals.TLS.Enable && vals.TLS.Address.String() == "" {
415 return xerrors.Errorf("TLS address must be set if TLS is enabled")
416 }
417 if !vals.TLS.Enable && vals.HTTPAddress.String() == "" {
418 return xerrors.Errorf("TLS is disabled. Enable with --tls-enable or specify a HTTP address")
419 }
420
421 if vals.AccessURL.String() != "" &&
422 !(vals.AccessURL.Scheme == "http" || vals.AccessURL.Scheme == "https") {
423 return xerrors.Errorf("access-url must include a scheme (e.g. 'http://' or 'https://)")
424 }
425
426 // Cross-field configuration validation after initial parsing.
427 if err := vals.Validate(); err != nil {
428 return err

Callers 3

AGPLMethod · 0.95
ServeFunction · 0.45
ServeConnV2Method · 0.45

Calls 15

ValidateMethod · 0.95
createConfigMethod · 0.95
TimeoutMethod · 0.95
CloseMethod · 0.95
CloseMethod · 0.95
ServeMethod · 0.95
RunMethod · 0.95
VerbosefMethod · 0.95
NewFunction · 0.92

Tested by

no test coverage detected