Skip to content

Commit 0f52b7d

Browse files
committed
refactor: update code layout be to consistent with our newer servers (skeleton layout)
1 parent 374af5f commit 0f52b7d

34 files changed

+156
-154
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ _testmain.go
6060
*.prof
6161
cpuprofile
6262

63-
tr1d1um
63+
./tr1d1um
6464
.ignore
6565
.vscode
6666
.yaml

main.go renamed to cmd/tr1d1um/main.go

Lines changed: 18 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"github.com/xmidt-org/arrange/arrangepprof"
1818
"github.com/xmidt-org/touchstone"
1919
"github.com/xmidt-org/touchstone/touchhttp"
20+
tr1d1um "github.com/xmidt-org/tr1d1um/internal"
2021
"go.uber.org/fx"
2122
"go.uber.org/zap"
2223

@@ -25,32 +26,8 @@ import (
2526
"github.com/xmidt-org/candlelight"
2627
)
2728

28-
// convenient global values
2929
const (
30-
DefaultKeyID = "current"
31-
apiVersion = "v3"
32-
prevAPIVersion = "v2"
33-
applicationName = "tr1d1um"
34-
apiBase = "api/" + apiVersion
35-
prevAPIBase = "api/" + prevAPIVersion
36-
apiBaseDualVersion = "api/{version:" + apiVersion + "|" + prevAPIVersion + "}"
37-
)
38-
39-
const (
40-
translationServicesKey = "supportedServices"
41-
targetURLKey = "targetURL"
42-
netDialerTimeoutKey = "netDialerTimeout"
43-
clientTimeoutKey = "clientTimeout"
44-
reqTimeoutKey = "respWaitTimeout"
45-
reqRetryIntervalKey = "requestRetryInterval"
46-
reqMaxRetriesKey = "requestMaxRetries"
47-
wrpSourceKey = "WRPSource"
48-
hooksSchemeKey = "hooksScheme"
49-
reducedTransactionLoggingCodesKey = "logging.reducedLoggingResponseCodes"
50-
authAcquirerKey = "authAcquirer"
51-
webhookConfigKey = "webhook"
52-
anclaClientConfigKey = "webhook.BasicClientConfig"
53-
tracingConfigKey = "tracing"
30+
tracingConfigKey = "tracing"
5431
)
5532

5633
var (
@@ -60,26 +37,14 @@ var (
6037
Commit string
6138
)
6239

63-
var defaults = map[string]interface{}{
64-
translationServicesKey: []string{}, // no services allowed by the default
65-
targetURLKey: "localhost:6000",
66-
netDialerTimeoutKey: "5s",
67-
clientTimeoutKey: "50s",
68-
reqTimeoutKey: "40s",
69-
reqRetryIntervalKey: "2s",
70-
reqMaxRetriesKey: 2,
71-
wrpSourceKey: "dns:localhost",
72-
hooksSchemeKey: "https",
73-
}
74-
7540
type XmidtClientTimeoutConfigIn struct {
7641
fx.In
77-
XmidtClientTimeout httpClientTimeout `name:"xmidtClientTimeout"`
42+
XmidtClientTimeout tr1d1um.HttpClientTimeout `name:"xmidtClientTimeout"`
7843
}
7944

8045
type ArgusClientTimeoutConfigIn struct {
8146
fx.In
82-
ArgusClientTimeout httpClientTimeout `name:"argusClientTimeout"`
47+
ArgusClientTimeout tr1d1um.HttpClientTimeout `name:"argusClientTimeout"`
8348
}
8449

8550
type TracingConfigIn struct {
@@ -95,11 +60,11 @@ type ConstOut struct {
9560

9661
func consts() ConstOut {
9762
return ConstOut{
98-
DefaultKeyID: DefaultKeyID,
63+
DefaultKeyID: tr1d1um.DefaultKeyID,
9964
}
10065
}
10166

102-
func configureXmidtClientTimeout(in XmidtClientTimeoutConfigIn) httpClientTimeout {
67+
func configureXmidtClientTimeout(in XmidtClientTimeoutConfigIn) tr1d1um.HttpClientTimeout {
10368
xct := in.XmidtClientTimeout
10469

10570
if xct.ClientTimeout == 0 {
@@ -114,7 +79,7 @@ func configureXmidtClientTimeout(in XmidtClientTimeoutConfigIn) httpClientTimeou
11479
return xct
11580
}
11681

117-
func configureArgusClientTimeout(in ArgusClientTimeoutConfigIn) httpClientTimeout {
82+
func configureArgusClientTimeout(in ArgusClientTimeoutConfigIn) tr1d1um.HttpClientTimeout {
11883
act := in.ArgusClientTimeout
11984

12085
if act.ClientTimeout == 0 {
@@ -128,7 +93,7 @@ func configureArgusClientTimeout(in ArgusClientTimeoutConfigIn) httpClientTimeou
12893

12994
func loadTracing(in TracingConfigIn) (candlelight.Tracing, error) {
13095
traceConfig := in.TracingConfig
131-
traceConfig.ApplicationName = applicationName
96+
traceConfig.ApplicationName = tr1d1um.ApplicationName
13297
tracing, err := candlelight.New(traceConfig)
13398
if err != nil {
13499
return candlelight.Tracing{}, err
@@ -150,7 +115,7 @@ func printVersion(f *pflag.FlagSet, arguments []string) (bool, error) {
150115
}
151116

152117
func printVersionInfo(writer io.Writer) {
153-
fmt.Fprintf(writer, "%s:\n", applicationName)
118+
fmt.Fprintf(writer, "%s:\n", tr1d1um.ApplicationName)
154119
fmt.Fprintf(writer, " version: \t%s\n", Version)
155120
fmt.Fprintf(writer, " go version: \t%s\n", runtime.Version())
156121
fmt.Fprintf(writer, " built time: \t%s\n", Date)
@@ -169,8 +134,8 @@ func exitIfError(logger *zap.Logger, err error) {
169134
}
170135

171136
//nolint:funlen
172-
func tr1d1um(arguments []string) (exitCode int) {
173-
v, l, f, err := setup(arguments)
137+
func Tr1d1um(arguments []string) (exitCode int) {
138+
v, l, f, err := tr1d1um.Setup(arguments)
174139
if err != nil {
175140
fmt.Fprintln(os.Stderr, err)
176141
return 1
@@ -189,8 +154,8 @@ func tr1d1um(arguments []string) (exitCode int) {
189154
fx.Supply(l),
190155
fx.Supply(v),
191156
arrange.ForViper(v),
192-
arrange.ProvideKey("xmidtClientTimeout", httpClientTimeout{}),
193-
arrange.ProvideKey("argusClientTimeout", httpClientTimeout{}),
157+
arrange.ProvideKey("xmidtClientTimeout", tr1d1um.HttpClientTimeout{}),
158+
arrange.ProvideKey("argusClientTimeout", tr1d1um.HttpClientTimeout{}),
194159
touchstone.Provide(),
195160
touchhttp.Provide(),
196161
anclafx.Provide(),
@@ -209,11 +174,11 @@ func tr1d1um(arguments []string) (exitCode int) {
209174
Target: configureArgusClientTimeout,
210175
},
211176
loadTracing,
212-
provideAnclaHTTPClient,
177+
tr1d1um.ProvideAnclaHTTPClient,
213178
),
214-
provideAuthChain("authx.inbound"),
215-
provideServers(),
216-
provideHandlers(),
179+
tr1d1um.ProvideAuthChain("authx.inbound"),
180+
tr1d1um.ProvideServers(),
181+
tr1d1um.ProvideHandlers(),
217182
)
218183

219184
switch err := app.Err(); {
@@ -230,5 +195,5 @@ func tr1d1um(arguments []string) (exitCode int) {
230195
}
231196

232197
func main() {
233-
os.Exit(tr1d1um(os.Args))
198+
os.Exit(Tr1d1um(os.Args))
234199
}

tr1d1um.yaml renamed to cmd/tr1d1um/tr1d1um.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ logging:
9191
# OutputPaths is a list of URLs or file paths to write logging output to.
9292
outputPaths:
9393
- stdout
94-
# - /var/log/tr1d1um/tr1d1um.log
9594

9695
# Level is the minimum enabled logging level. Note that this is a dynamic
9796
# level, so calling Config.Level.SetLevel will atomically change the log
@@ -102,7 +101,6 @@ logging:
102101
# zapcore.EncoderConfig for details.
103102
errorOutputPaths:
104103
- stderr
105-
- denopink-tr1d1um.log
106104

107105
# EncoderConfig sets options for the chosen encoder. See
108106
# zapcore.EncoderConfig for details.

acquire.go renamed to internal/acquire.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// SPDX-FileCopyrightText: 2022 Comcast Cable Communications Management, LLC
22
// SPDX-License-Identifier: Apache-2.0
33

4-
package main
4+
package tr1d1um
55

66
import (
77
"encoding/json"

auth.go renamed to internal/auth.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// SPDX-FileCopyrightText: 2022 Comcast Cable Communications Management, LLC
22
// SPDX-License-Identifier: Apache-2.0
33

4-
package main
4+
package tr1d1um
55

66
import (
77
"errors"
@@ -31,7 +31,7 @@ type JWTValidator struct {
3131
Leeway bascule.Leeway
3232
}
3333

34-
func provideAuthChain(configKey string) fx.Option {
34+
func ProvideAuthChain(configKey string) fx.Option {
3535
return fx.Options(
3636
basculehttp.ProvideMetrics(),
3737
basculechecks.ProvideMetrics(),

basculeLogging.go renamed to internal/basculeLogging.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// SPDX-FileCopyrightText: 2022 Comcast Cable Communications Management, LLC
22
// SPDX-License-Identifier: Apache-2.0
33

4-
package main
4+
package tr1d1um
55

66
import (
77
"net/http"

basculeLogging_test.go renamed to internal/basculeLogging_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// SPDX-FileCopyrightText: 2022 Comcast Cable Communications Management, LLC
22
// SPDX-License-Identifier: Apache-2.0
33

4-
package main
4+
package tr1d1um_test
55

66
import (
77
"net/http"

primaryHandler.go renamed to internal/primaryHandler.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// SPDX-FileCopyrightText: 2022 Comcast Cable Communications Management, LLC
22
// SPDX-License-Identifier: Apache-2.0
33

4-
package main
4+
package tr1d1um
55

66
import (
77
"errors"
@@ -18,18 +18,18 @@ import (
1818
"github.com/xmidt-org/candlelight"
1919
"github.com/xmidt-org/touchstone"
2020
"github.com/xmidt-org/touchstone/touchhttp"
21-
"github.com/xmidt-org/tr1d1um/stat"
22-
"github.com/xmidt-org/tr1d1um/transaction"
23-
"github.com/xmidt-org/tr1d1um/translation"
21+
"github.com/xmidt-org/tr1d1um/internal/stat"
22+
"github.com/xmidt-org/tr1d1um/internal/transaction"
23+
"github.com/xmidt-org/tr1d1um/internal/translation"
2424
webhook "github.com/xmidt-org/webhook-schema"
2525
"github.com/xmidt-org/webpa-common/v2/xhttp"
2626
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
2727
"go.uber.org/fx"
2828
"go.uber.org/zap"
2929
)
3030

31-
// httpClientTimeout contains timeouts for an HTTP client and its requests.
32-
type httpClientTimeout struct {
31+
// HttpClientTimeout contains timeouts for an HTTP client and its requests.
32+
type HttpClientTimeout struct {
3333
// ClientTimeout is HTTP Client Timeout.
3434
ClientTimeout time.Duration
3535

@@ -60,7 +60,7 @@ type provideWebhookHandlersIn struct {
6060
type provideAnclaHTTPClientIn struct {
6161
fx.In
6262

63-
ArgusClientTimeout httpClientTimeout `name:"argus_client_timeout"`
63+
ArgusClientTimeout HttpClientTimeout `name:"argus_client_timeout"`
6464
Tracing candlelight.Tracing
6565
}
6666

@@ -74,7 +74,7 @@ type provideWebhookHandlersOut struct {
7474
type ServiceOptionsIn struct {
7575
fx.In
7676
Logger *zap.Logger
77-
XmidtClientTimeout httpClientTimeout `name:"xmidt_client_timeout"`
77+
XmidtClientTimeout HttpClientTimeout `name:"xmidt_client_timeout"`
7878
RequestMaxRetries int `name:"requestMaxRetries"`
7979
RequestRetryInterval time.Duration `name:"requestRetryInterval"`
8080
TargetURL string `name:"targetURL"`
@@ -88,11 +88,11 @@ type ServiceOptionsOut struct {
8888
TranslationServiceOptions *translation.ServiceOptions
8989
}
9090

91-
func provideAnclaHTTPClient(in provideAnclaHTTPClientIn) chrysom.HTTPClient {
91+
func ProvideAnclaHTTPClient(in provideAnclaHTTPClientIn) chrysom.HTTPClient {
9292
return newHTTPClient(in.ArgusClientTimeout, in.Tracing)
9393
}
9494

95-
func newHTTPClient(timeouts httpClientTimeout, tracing candlelight.Tracing) *http.Client {
95+
func newHTTPClient(timeouts HttpClientTimeout, tracing candlelight.Tracing) *http.Client {
9696
var transport http.RoundTripper = &http.Transport{
9797
Dial: (&net.Dialer{
9898
Timeout: timeouts.NetDialerTimeout,
@@ -162,7 +162,7 @@ func provideWebhookHandlers(in provideWebhookHandlersIn) (out provideWebhookHand
162162
return
163163
}
164164

165-
func provideHandlers() fx.Option {
165+
func ProvideHandlers() fx.Option {
166166
return fx.Options(
167167
arrange.ProvideKey(authAcquirerKey, authAcquirerConfig{}),
168168
fx.Provide(

routes.go renamed to internal/routes.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
// SPDX-FileCopyrightText: 2022 Comcast Cable Communications Management, LLC
22
// SPDX-License-Identifier: Apache-2.0
33

4-
package main
4+
package tr1d1um
55

66
import (
77
"bytes"
88
"context"
99
"encoding/json"
1010
"errors"
1111
"fmt"
12-
"io/ioutil"
12+
"io"
1313
"net/http"
1414
"os"
1515
"time"
@@ -26,8 +26,8 @@ import (
2626
"github.com/xmidt-org/sallust/sallusthttp"
2727
"github.com/xmidt-org/touchstone"
2828
"github.com/xmidt-org/touchstone/touchhttp"
29-
"github.com/xmidt-org/tr1d1um/stat"
30-
"github.com/xmidt-org/tr1d1um/translation"
29+
"github.com/xmidt-org/tr1d1um/internal/stat"
30+
"github.com/xmidt-org/tr1d1um/internal/translation"
3131
webhook "github.com/xmidt-org/webhook-schema"
3232
"go.opentelemetry.io/contrib/instrumentation/github.com/gorilla/mux/otelmux"
3333
"go.uber.org/fx"
@@ -115,7 +115,7 @@ type metricsRoutesIn struct {
115115
Handler touchhttp.Handler
116116
}
117117

118-
func provideServers() fx.Option {
118+
func ProvideServers() fx.Option {
119119
return fx.Options(
120120
arrange.ProvideKey(reqMaxRetriesKey, 0),
121121
arrange.ProvideKey(reqRetryIntervalKey, time.Duration(0)),
@@ -315,7 +315,7 @@ func fixV2Duration(getLogger func(context.Context) *zap.Logger, config ancla.TTL
315315
// the v2 handler.
316316
logger := sallusthttp.Get(r)
317317

318-
requestPayload, err := ioutil.ReadAll(r.Body)
318+
requestPayload, err := io.ReadAll(r.Body)
319319
if err != nil {
320320
v2ErrEncode(w, logger, err, 0)
321321
return
@@ -366,7 +366,7 @@ func fixV2Duration(getLogger func(context.Context) *zap.Logger, config ancla.TTL
366366
if err != nil {
367367
v2ErrEncode(w, logger, fmt.Errorf("failed to recreate request body: %v", err), 0)
368368
}
369-
r.Body = ioutil.NopCloser(bytes.NewBuffer(body))
369+
r.Body = io.NopCloser(bytes.NewBuffer(body))
370370

371371
if v2Handler == nil {
372372
v2Handler = next

0 commit comments

Comments
 (0)