Skip to content

Commit

Permalink
fix: decoding content
Browse files Browse the repository at this point in the history
  • Loading branch information
jeroenrinzema committed Dec 2, 2020
1 parent aff484b commit b9e9342
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
9 changes: 7 additions & 2 deletions cmd/semaphore/daemon/config/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package config

import (
"mime"
"path/filepath"

"github.com/jexia/semaphore"
"github.com/jexia/semaphore/cmd/semaphore/daemon/providers"
Expand Down Expand Up @@ -69,6 +70,10 @@ type GraphQL struct {
// read options.
func SetOptions(ctx *broker.Context, flags *Daemon) error {
for _, path := range flags.Files {
if mime.TypeByExtension(filepath.Ext(path)) != providers.HCLExtensionType {
continue
}

options, err := hcl.GetOptions(ctx, path)
if err != nil {
return err
Expand Down Expand Up @@ -137,7 +142,7 @@ func NewCore(ctx *broker.Context, flags *Daemon) (semaphore.Options, error) {
}

for _, path := range flags.Files {
switch mime.TypeByExtension(path) {
switch mime.TypeByExtension(filepath.Ext(path)) {
case providers.JSONExtensionType:
options = append(options, semaphore.WithFlows(jsonSpecs.FlowsResolver(path)))
default:
Expand All @@ -159,7 +164,7 @@ func NewProviders(ctx *broker.Context, core semaphore.Options, params *Daemon) (
var options []providers.Option

for _, path := range params.Files {
switch mime.TypeByExtension(path) {
switch mime.TypeByExtension(filepath.Ext(path)) {
case providers.JSONExtensionType:
options = append(options, providers.WithServices(jsonSpecs.ServicesResolver(path)))
options = append(options, providers.WithEndpoints(jsonSpecs.EndpointsResolver(path)))
Expand Down
1 change: 1 addition & 0 deletions pkg/providers/hcl/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package hcl
// Options represents the available options that could be defined inside a HCL definition
type Options struct {
LogLevel string
Includes []string
Protobuffers []string
Openapi3 []string
GraphQL *GraphQL
Expand Down
9 changes: 6 additions & 3 deletions pkg/providers/json/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,13 @@ func resolvePath(ctx *broker.Context, path string) (collection, error) {
return collection{}, err
}

collection := collection{}
json.Unmarshal(bb, &collection)
content := collection{}
err = json.Unmarshal(bb, &content)
if err != nil {
return collection{}, err
}

result.Append(collection)
result.Append(content)
}

logger.Debug(ctx, "resolve path result", zap.String("path", path), zap.Int("manifests", len(files)))
Expand Down

0 comments on commit b9e9342

Please sign in to comment.