github.com/weaviate/weaviate@v1.24.6/test/docker/container.go (about)

     1  //                           _       _
     2  // __      _____  __ ___   ___  __ _| |_ ___
     3  // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
     4  //  \ V  V /  __/ (_| |\ V /| | (_| | ||  __/
     5  //   \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
     6  //
     7  //  Copyright © 2016 - 2024 Weaviate B.V. All rights reserved.
     8  //
     9  //  CONTACT: hello@weaviate.io
    10  //
    11  
    12  package docker
    13  
    14  import (
    15  	"github.com/docker/go-connections/nat"
    16  	"github.com/testcontainers/testcontainers-go"
    17  )
    18  
    19  type EndpointName string
    20  
    21  var (
    22  	HTTP EndpointName = "http"
    23  	GRPC EndpointName = "grpc"
    24  )
    25  
    26  type endpoint struct {
    27  	port nat.Port
    28  	uri  string
    29  }
    30  
    31  type DockerContainer struct {
    32  	name        string
    33  	endpoints   map[EndpointName]endpoint
    34  	container   testcontainers.Container
    35  	envSettings map[string]string
    36  }
    37  
    38  func (d *DockerContainer) Name() string {
    39  	return d.name
    40  }
    41  
    42  func (d *DockerContainer) URI() string {
    43  	return d.GetEndpoint(HTTP)
    44  }
    45  
    46  func (d *DockerContainer) GetEndpoint(name EndpointName) string {
    47  	if endpoint, ok := d.endpoints[name]; ok {
    48  		return endpoint.uri
    49  	}
    50  	return ""
    51  }