Skip to content

Commit

Permalink
Merge pull request #150 from launchdarkly/eb/ch83491/core-packages-5
Browse files Browse the repository at this point in the history
(v6 - #18) move all remaining core stuff into core, clean up tests, move Relay app starter to main package
  • Loading branch information
eli-darkly authored Aug 4, 2020
2 parents fba729c + 75aaab9 commit 0bff9a7
Show file tree
Hide file tree
Showing 92 changed files with 363 additions and 290 deletions.
4 changes: 4 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ issues:
- path: core/sharedtest/
linters:
- golint # don't need linter warnings about comment formatting etc. on our test helpers
- path: core/sharedtest/testsuites/
linters:
- bodyclose
- goconst
exclude:
# golint exclusions
- "(const|func|method|struct field|type|var) .* should be " # golint errors about variable names (don't want to fix them because they're in a public interface)
Expand Down
2 changes: 1 addition & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ project_name: ld-relay
builds:
- env:
- CGO_ENABLED=0
main: ./cmd/ld-relay/
main: .
binary: ld-relay
# Default is `-s -w -X main.version={{.Version}} -X main.commit={{.ShortCommit}} -X main.date={{.Date}}`.
ldflags:
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ ENV CGO_ENABLED=0
ENV GOOS=linux
ENV GOPATH=/go

RUN go build -a -o ldr ./cmd/ld-relay
RUN go build -a -o ldr .

FROM golang:1.13.12-alpine

Expand Down
2 changes: 1 addition & 1 deletion core/application/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"net/http"

"github.com/launchdarkly/ld-relay/v6/config"
"github.com/launchdarkly/ld-relay/v6/core/config"
"gopkg.in/launchdarkly/go-sdk-common.v2/ldlog"
)

Expand Down
17 changes: 5 additions & 12 deletions client-side.go → core/client-side.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package relay
package core

import (
"bytes"
Expand All @@ -7,19 +7,12 @@ import (
"net/http/httptest"
"strconv"

"github.com/launchdarkly/ld-relay/v6/core/internal/browser"
"github.com/launchdarkly/ld-relay/v6/core/internal/events"
"github.com/launchdarkly/ld-relay/v6/core/internal/util"
"github.com/launchdarkly/ld-relay/v6/core/middleware"
"github.com/launchdarkly/ld-relay/v6/internal/events"
"github.com/launchdarkly/ld-relay/v6/internal/util"
)

const transparent1PixelImgBase64 = "R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7="

var transparent1PixelImg []byte

func init() {
transparent1PixelImg, _ = base64.StdEncoding.DecodeString(transparent1PixelImgBase64)
}

func getEventsImage(w http.ResponseWriter, req *http.Request) {
clientCtx := middleware.GetEnvContextInfo(req.Context())

Expand Down Expand Up @@ -49,7 +42,7 @@ func getEventsImage(w http.ResponseWriter, req *http.Request) {
}

w.Header().Set("Content-Type", "image/gif")
w.Write(transparent1PixelImg)
w.Write(browser.Transparent1PixelImageData)
}

func getGoals(w http.ResponseWriter, req *http.Request) {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion core/httpconfig/httpconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"errors"
"net/http"

"github.com/launchdarkly/ld-relay/v6/config"
"github.com/launchdarkly/ld-relay/v6/core/config"
"github.com/launchdarkly/ld-relay/v6/internal/version"
"gopkg.in/launchdarkly/go-sdk-common.v2/ldlog"
"gopkg.in/launchdarkly/go-server-sdk.v5/interfaces"
Expand Down
22 changes: 11 additions & 11 deletions core/internal/cors/cors.go → core/internal/browser/cors.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
package cors
package browser

import (
"context"
"net/http"
"strings"

"github.com/launchdarkly/ld-relay/v6/internal/events"
"github.com/launchdarkly/ld-relay/v6/core/internal/events"
)

const (
// The default origin string to use in CORS response headers.
DefaultAllowedOrigin = "*"
)

type contextKeyType string
type corsContextKeyType string

const (
contextKey contextKeyType = "context"
maxAge string = "300"
corsContextKey corsContextKeyType = "context"
maxAge string = "300"
)

var allowedHeadersList = []string{
Expand All @@ -33,27 +33,27 @@ var allowedHeadersList = []string{

var allowedHeaders = strings.Join(allowedHeadersList, ",")

// RequestContext represents a scope that has a specific set of allowed origins for CORS requests. This
// CORSContext represents a scope that has a specific set of allowed origins for CORS requests. This
// can be attached to a request context with WithCORSContext().
type RequestContext interface {
type CORSContext interface {
AllowedOrigins() []string
}

// GetCORSContext returns the CORSContext that has been attached to this Context with WithCORSContext(),
// or nil if none.
func GetCORSContext(ctx context.Context) RequestContext {
if cc, ok := ctx.Value(contextKey).(RequestContext); ok {
func GetCORSContext(ctx context.Context) CORSContext {
if cc, ok := ctx.Value(corsContextKey).(CORSContext); ok {
return cc
}
return nil
}

// WithCORSContext returns a copy of the parent context with the specified CORSContext attached.
func WithCORSContext(parent context.Context, cc RequestContext) context.Context {
func WithCORSContext(parent context.Context, cc CORSContext) context.Context {
if cc == nil {
return parent
}
return context.WithValue(parent, contextKey, cc)
return context.WithValue(parent, corsContextKey, cc)
}

// SetCORSHeaders sets a standard set of CORS headers on an HTTP response. This is meant to be the same
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cors
package browser

import (
"context"
Expand Down
2 changes: 2 additions & 0 deletions core/internal/browser/package_info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Package browser contains internal helpers that are only used for browser requests.
package browser
12 changes: 12 additions & 0 deletions core/internal/browser/pixel_image.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package browser

import "encoding/base64"

const Transparent1PixelImgBase64 = "R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7="

var Transparent1PixelImageData []byte = makePixelImageData()

func makePixelImageData() []byte {
data, _ := base64.StdEncoding.DecodeString(Transparent1PixelImgBase64)
return data
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import (

"gopkg.in/launchdarkly/go-sdk-common.v2/ldlog"

c "github.com/launchdarkly/ld-relay/v6/config"
c "github.com/launchdarkly/ld-relay/v6/core/config"
"github.com/launchdarkly/ld-relay/v6/core/httpconfig"
"github.com/launchdarkly/ld-relay/v6/internal/store"
"github.com/launchdarkly/ld-relay/v6/internal/util"
"github.com/launchdarkly/ld-relay/v6/core/internal/store"
"github.com/launchdarkly/ld-relay/v6/core/internal/util"
)

// Describes one of the possible endpoints (on both events.launchdarkly.com and the relay) for posting events
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import (
"gopkg.in/launchdarkly/go-server-sdk-evaluation.v1/ldmodel"
"gopkg.in/launchdarkly/go-server-sdk.v5/ldcomponents/ldstoreimpl"

c "github.com/launchdarkly/ld-relay/v6/config"
c "github.com/launchdarkly/ld-relay/v6/core/config"
"github.com/launchdarkly/ld-relay/v6/core/httpconfig"
"github.com/launchdarkly/ld-relay/v6/internal/store"
"github.com/launchdarkly/ld-relay/v6/core/internal/store"
)

type eventSummarizingRelay struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"encoding/json"
"testing"

"github.com/launchdarkly/ld-relay/v6/core/internal/store"
"github.com/launchdarkly/ld-relay/v6/core/sharedtest"
"github.com/launchdarkly/ld-relay/v6/internal/store"
ldevents "gopkg.in/launchdarkly/go-sdk-events.v1"
"gopkg.in/launchdarkly/go-server-sdk-evaluation.v1/ldbuilders"
"gopkg.in/launchdarkly/go-server-sdk.v5/interfaces"
Expand All @@ -18,7 +18,7 @@ import (
"gopkg.in/launchdarkly/go-sdk-common.v2/ldreason"
"gopkg.in/launchdarkly/go-sdk-common.v2/ldvalue"

relaystore "github.com/launchdarkly/ld-relay/v6/internal/store"
relaystore "github.com/launchdarkly/ld-relay/v6/core/internal/store"
)

func makeStoreAdapterWithExistingStore(store interfaces.DataStore) *store.SSERelayDataStoreAdapter {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

"gopkg.in/launchdarkly/go-sdk-common.v2/ldlog"

"github.com/launchdarkly/ld-relay/v6/config"
"github.com/launchdarkly/ld-relay/v6/core/config"
"github.com/launchdarkly/ld-relay/v6/internal/version"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/stretchr/testify/assert"

"github.com/launchdarkly/go-test-helpers/v2/httphelpers"
"github.com/launchdarkly/ld-relay/v6/config"
"github.com/launchdarkly/ld-relay/v6/core/config"
"gopkg.in/launchdarkly/go-sdk-common.v2/ldlog"
)

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"go.opencensus.io/stats/view"
"go.opencensus.io/trace"

"github.com/launchdarkly/ld-relay/v6/config"
"github.com/launchdarkly/ld-relay/v6/core/config"
"gopkg.in/launchdarkly/go-sdk-common.v2/ldlog"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/launchdarkly/ld-relay/v6/config"
"github.com/launchdarkly/ld-relay/v6/core/config"
"gopkg.in/launchdarkly/go-sdk-common.v2/ldlog"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"go.opencensus.io/stats/view"

"github.com/launchdarkly/ld-relay/v6/internal/events"
"github.com/launchdarkly/ld-relay/v6/core/internal/events"
)

type currentConnectionsMetric struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/launchdarkly/ld-relay/v6/internal/events"
"github.com/launchdarkly/ld-relay/v6/core/internal/events"
)

const testReportingPeriod = time.Millisecond
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package metrics

import (
"github.com/launchdarkly/ld-relay/v6/config"
"github.com/launchdarkly/ld-relay/v6/core/config"
"gopkg.in/launchdarkly/go-sdk-common.v2/ldlog"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"gopkg.in/launchdarkly/go-sdk-common.v2/ldlog"
"gopkg.in/launchdarkly/go-sdk-common.v2/ldlogtest"

"github.com/launchdarkly/ld-relay/v6/config"
"github.com/launchdarkly/ld-relay/v6/core/config"
)

func TestRegisterExporters(t *testing.T) {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import (

"github.com/pborman/uuid"

"github.com/launchdarkly/ld-relay/v6/config"
"github.com/launchdarkly/ld-relay/v6/internal/events"
"github.com/launchdarkly/ld-relay/v6/core/config"
"github.com/launchdarkly/ld-relay/v6/core/internal/events"
)

// Manager is the top-level object that controls all of our metrics exporter activity. It should be
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/launchdarkly/ld-relay/v6/config"
"github.com/launchdarkly/ld-relay/v6/core/config"
)

type args struct {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

"gopkg.in/launchdarkly/go-sdk-common.v2/ldlog"

"github.com/launchdarkly/ld-relay/v6/config"
"github.com/launchdarkly/ld-relay/v6/core/config"
"github.com/launchdarkly/ld-relay/v6/core/logging"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/stretchr/testify/require"

ct "github.com/launchdarkly/go-configtypes"
"github.com/launchdarkly/ld-relay/v6/config"
"github.com/launchdarkly/ld-relay/v6/core/config"
"gopkg.in/launchdarkly/go-sdk-common.v2/ldlog"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"gopkg.in/launchdarkly/go-sdk-common.v2/ldlog"

"github.com/launchdarkly/ld-relay/v6/config"
"github.com/launchdarkly/ld-relay/v6/core/config"
)

var stackdriverExporterType exporterType = stackdriverExporterTypeImpl{}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/stretchr/testify/require"

helpers "github.com/launchdarkly/go-test-helpers/v2"
"github.com/launchdarkly/ld-relay/v6/config"
"github.com/launchdarkly/ld-relay/v6/core/config"
"gopkg.in/launchdarkly/go-sdk-common.v2/ldlog"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"go.opencensus.io/trace"

"github.com/launchdarkly/ld-relay/v6/config"
"github.com/launchdarkly/ld-relay/v6/core/config"
"gopkg.in/launchdarkly/go-sdk-common.v2/ldlog"
)

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/stretchr/testify/require"

"github.com/launchdarkly/ld-relay/v6/config"
"github.com/launchdarkly/ld-relay/v6/core/config"
"github.com/launchdarkly/ld-relay/v6/core/sharedtest"
"gopkg.in/launchdarkly/go-server-sdk-evaluation.v1/ldbuilders"
"gopkg.in/launchdarkly/go-server-sdk.v5/interfaces"
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion core/middleware/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package middleware
import (
"context"

"github.com/launchdarkly/ld-relay/v6/config"
"github.com/launchdarkly/ld-relay/v6/core/config"
"github.com/launchdarkly/ld-relay/v6/core/relayenv"
)

Expand Down
Loading

0 comments on commit 0bff9a7

Please sign in to comment.