Skip to content

Commit

Permalink
Use the canonical base URL when referencing Bees' logos in API
Browse files Browse the repository at this point in the history
  • Loading branch information
muesli committed Feb 19, 2017
1 parent 5683402 commit 8cf2b60
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
5 changes: 3 additions & 2 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,14 @@ func Run() {
// to see what happens in the package, uncomment the following
//restful.TraceLogger(log.New(os.Stdout, "[restful] ", log.LstdFlags|log.Lshortfile))

context := &context.APIContext{}

// Setup web-service
smolderConfig := smolder.APIConfig{
BaseURL: canonicalURL,
PathPrefix: "v1/",
}
context := &context.APIContext{
Config: smolderConfig,
}

wsContainer := smolder.NewSmolderContainer(smolderConfig, nil, nil)
wsContainer.Router(restful.CurlyRouter{})
Expand Down
5 changes: 4 additions & 1 deletion api/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,14 @@ import (

// APIContext is polly's central context
type APIContext struct {
Config smolder.APIConfig
}

// NewAPIContext returns a new polly context
func (context *APIContext) NewAPIContext() smolder.APIContext {
ctx := &APIContext{}
ctx := &APIContext{
Config: context.Config,
}
return ctx
}

Expand Down
15 changes: 10 additions & 5 deletions api/resources/hives/hives_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,15 @@
package hives

import (
"net/url"
"path"
"sort"

restful "github.com/emicklei/go-restful"
"github.com/muesli/beehive/bees"

"github.com/muesli/smolder"

"github.com/muesli/beehive/api/context"
"github.com/muesli/beehive/bees"
)

// HiveResponse is the common response to 'hive' requests
Expand Down Expand Up @@ -88,13 +91,15 @@ func (r *HiveResponse) EmptyResponse() interface{} {
return nil
}

func prepareHiveResponse(context smolder.APIContext, hive *bees.BeeFactoryInterface) hiveInfoResponse {
// ctx := context.(*context.APIContext)
func prepareHiveResponse(ctx smolder.APIContext, hive *bees.BeeFactoryInterface) hiveInfoResponse {
u, _ := url.Parse(ctx.(*context.APIContext).Config.BaseURL)
u.Path = path.Join(u.Path, "images", (*hive).Image())

resp := hiveInfoResponse{
ID: (*hive).ID(),
Name: (*hive).Name(),
Description: (*hive).Description(),
Image: "/images/" + (*hive).Image(),
Image: u.String(),
LogoColor: (*hive).LogoColor(),
Options: (*hive).Options(),
Events: (*hive).Events(),
Expand Down

0 comments on commit 8cf2b60

Please sign in to comment.