diff --git a/main.go b/main.go index ece53ba5..d58749ca 100644 --- a/main.go +++ b/main.go @@ -112,6 +112,7 @@ type serverOptions struct { HTTPBind string ServiceOptions svc.Options Debug bool + svc api.ServerServer } func serverOptionsFromCliContext(c *cli.Context) serverOptions { @@ -132,6 +133,12 @@ func server(c *cli.Context) error { opts := serverOptionsFromCliContext(c) + svc, err := svc.New(opts.ServiceOptions) + if err != nil { + return errors.Wrap(err, "failed to initialize service") + } + opts.svc = svc + errs := make(chan error) go func() { errs <- errors.Wrap(startGRPCServer(ctx, &opts), "gRPC server error") }() go func() { errs <- errors.Wrap(startHTTPServer(ctx, &opts), "HTTP server error") }() @@ -157,6 +164,7 @@ func startHTTPServer(ctx context.Context, opts *serverOptions) error { if err := views.Setup(&views.Options{ Router: router, Debug: opts.Debug, + Svc: opts.svc, }); err != nil { return errors.Wrap(err, "failed to setup views") } @@ -224,11 +232,7 @@ func startGRPCServer(ctx context.Context, opts *serverOptions) error { grpc.UnaryInterceptor(grpc_middleware.ChainUnaryServer(serverUnaryOpts...)), ) - svc, err := svc.New(opts.ServiceOptions) - if err != nil { - return errors.Wrap(err, "failed to initialize service") - } - api.RegisterServerServer(grpcServer, svc) + api.RegisterServerServer(grpcServer, opts.svc) //if opts.WithReflection { reflection.Register(grpcServer) //} diff --git a/pkg/dashboard/dashboard.go b/pkg/dashboard/dashboard.go index 459af543..743c3c57 100644 --- a/pkg/dashboard/dashboard.go +++ b/pkg/dashboard/dashboard.go @@ -15,13 +15,14 @@ func (e *Entries) append(entries ...*Entry) { } } -func NewManualEntry(title, URL, imageURL, description string, kind Entry_Kind) *Entry { +func NewManualEntry(title, URL, imageURL, description string, kind Entry_Kind, isExternal bool) *Entry { return &Entry{ Title: title, URL: URL, Description: description, ImageURL: imageURL, Kind: kind, + IsExternal: isExternal, } } @@ -46,8 +47,22 @@ func newEntries() *Entries { func (d *Dashboard) hackEntries(limit int) (*Entries, error) { entries := newEntries() - entries.append(NewManualEntry("Moi j'aime", "hackz/moijaime", "", "Générateur de phrase de moi j'aime", Entry_Hack)) - entries.append(NewManualEntry("3615cryptage", "hackz/3615cryptage", "", "Messages codés de James Bond", Entry_Hack)) + entries.append(NewManualEntry( + "Moi j'aime", + "hackz/moijaime", + "", + "Générateur de phrase de moi j'aime", + Entry_Hack, + false, + )) + entries.append(NewManualEntry( + "3615cryptage", + "hackz/3615cryptage", + "", + "Messages codés de James Bond", + Entry_Hack, + false, + )) entries.shuffle() if len(entries.Entries) < limit { @@ -81,6 +96,7 @@ func (d *Dashboard) trackEntries(limit int) (*Entries, error) { track.ArtworkUrl, track.Description, Entry_Track, + false, )) } @@ -102,6 +118,7 @@ func (d *Dashboard) merchEntries(limit int) (Entries, error) { product.ImageURL, "", Entry_Merch, + true, )) } diff --git a/pkg/dashboard/dashboard.pb.go b/pkg/dashboard/dashboard.pb.go index 7a41fa09..a9705ef8 100644 --- a/pkg/dashboard/dashboard.pb.go +++ b/pkg/dashboard/dashboard.pb.go @@ -103,7 +103,8 @@ type Entry struct { URL string `protobuf:"bytes,2,opt,name=url,proto3" json:"url,omitempty"` Description string `protobuf:"bytes,3,opt,name=description,proto3" json:"description,omitempty"` ImageURL string `protobuf:"bytes,4,opt,name=image_url,json=imageUrl,proto3" json:"image_url,omitempty"` - Kind Entry_Kind `protobuf:"varint,5,opt,name=kind,proto3,enum=calcbiz.dashboard.Entry_Kind" json:"kind,omitempty"` + IsExternal bool `protobuf:"varint,5,opt,name=is_external,json=isExternal,proto3" json:"is_external,omitempty"` + Kind Entry_Kind `protobuf:"varint,6,opt,name=kind,proto3,enum=calcbiz.dashboard.Entry_Kind" json:"kind,omitempty"` } func (m *Entry) Reset() { *m = Entry{} } @@ -167,6 +168,13 @@ func (m *Entry) GetImageURL() string { return "" } +func (m *Entry) GetIsExternal() bool { + if m != nil { + return m.IsExternal + } + return false +} + func (m *Entry) GetKind() Entry_Kind { if m != nil { return m.Kind @@ -183,30 +191,31 @@ func init() { func init() { proto.RegisterFile("pkg/dashboard/dashboard.proto", fileDescriptor_86c4470626934ef2) } var fileDescriptor_86c4470626934ef2 = []byte{ - // 363 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x91, 0x3d, 0x4f, 0xe3, 0x30, - 0x1c, 0xc6, 0xe3, 0x26, 0xb9, 0x36, 0xee, 0xdd, 0xa9, 0x67, 0xdd, 0x90, 0xab, 0xae, 0x69, 0xd4, - 0xa9, 0x0c, 0x24, 0xa2, 0x08, 0x89, 0x85, 0xa5, 0x12, 0x12, 0x08, 0x58, 0x22, 0xba, 0xb0, 0x20, - 0x27, 0x71, 0x53, 0xab, 0xa9, 0x1d, 0x39, 0xce, 0x00, 0x9f, 0x82, 0x8f, 0xc5, 0xd8, 0x91, 0xa9, - 0x42, 0xe9, 0x07, 0xe0, 0x2b, 0x20, 0x3b, 0xbc, 0x0a, 0xb1, 0x3d, 0xcf, 0xef, 0xff, 0xfc, 0x5f, - 0x64, 0xc3, 0x41, 0xb1, 0xcc, 0xc2, 0x14, 0x97, 0x8b, 0x98, 0x63, 0x91, 0xbe, 0xab, 0xa0, 0x10, - 0x5c, 0x72, 0xf4, 0x27, 0xc1, 0x79, 0x12, 0xd3, 0xdb, 0xe0, 0xad, 0xd0, 0xff, 0x9f, 0x71, 0x9e, - 0xe5, 0x24, 0xc4, 0x05, 0x0d, 0x31, 0x63, 0x5c, 0x62, 0x49, 0x39, 0x2b, 0x9b, 0x86, 0xfe, 0x6e, - 0x46, 0xe5, 0xa2, 0x8a, 0x83, 0x84, 0xaf, 0xc2, 0x8c, 0x67, 0x3c, 0xd4, 0x38, 0xae, 0xe6, 0xda, - 0x69, 0xa3, 0x55, 0x13, 0x1f, 0x1d, 0xc1, 0xf6, 0x31, 0x93, 0x82, 0x92, 0x12, 0x4d, 0x60, 0x9b, - 0x34, 0xd2, 0x05, 0xbe, 0x39, 0xee, 0x4e, 0xdc, 0xe0, 0xcb, 0xf2, 0x40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0xff, 0x48, 0x02, 0x7f, 0x43, 0xf2, 0x01, 0x00, 0x00, + // 384 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x91, 0xbf, 0xae, 0xd3, 0x30, + 0x14, 0xc6, 0xe3, 0x26, 0x69, 0x13, 0x17, 0x50, 0xb1, 0x18, 0x42, 0x45, 0xd3, 0xa8, 0x53, 0x18, + 0x48, 0x44, 0x11, 0x12, 0x0b, 0x4b, 0xa5, 0x4a, 0x20, 0x60, 0x89, 0xe8, 0xc2, 0x52, 0x39, 0x89, + 0x9b, 0x5a, 0x4d, 0xed, 0xc8, 0x71, 0x24, 0xe0, 0x29, 0xfa, 0x58, 0x8c, 0x1d, 0x99, 0xaa, 0xab, + 0xf4, 0x45, 0xae, 0xec, 0xf4, 0xfe, 0xd3, 0xd5, 0xdd, 0xbe, 0xef, 0x77, 0xbe, 0x73, 0x8e, 0xad, + 0x03, 0x27, 0xd5, 0xae, 0x88, 0x73, 0x5c, 0x6f, 0x53, 0x8e, 0x45, 0x7e, 0xa7, 0xa2, 0x4a, 0x70, + 0xc9, 0xd1, 0xcb, 0x0c, 0x97, 0x59, 0x4a, 0xff, 0x46, 0xb7, 0x85, 0xf1, 0x9b, 0x82, 0xf3, 0xa2, + 0x24, 0x31, 0xae, 0x68, 0x8c, 0x19, 0xe3, 0x12, 0x4b, 0xca, 0x59, 0xdd, 0x35, 0x8c, 0xdf, 0x15, + 0x54, 0x6e, 0x9b, 0x34, 0xca, 0xf8, 0x3e, 0x2e, 0x78, 0xc1, 0x63, 0x8d, 0xd3, 0x66, 0xa3, 0x9d, + 0x36, 0x5a, 0x75, 0xf1, 0xd9, 0x67, 0x38, 0x58, 0x32, 0x29, 0x28, 0xa9, 0xd1, 0x1c, 0x0e, 0x48, + 0x27, 0x3d, 0x10, 0x98, 0xe1, 0x70, 0xee, 0x45, 0x8f, 0x96, 0x47, 0x2a, 0xfc,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, 0x29, 0x48, 0xb4, 0x27, 0xf1, 0x65, 0x7b, 0xfc, 0xe0, 0xf6, 0x69, 0x5f, 0x9f, + 0xe4, 0xc3, 0x75, 0x00, 0x00, 0x00, 0xff, 0xff, 0x92, 0xdc, 0x98, 0x80, 0x13, 0x02, 0x00, 0x00, } func (m *Entries) Marshal() (dAtA []byte, err error) { @@ -278,9 +287,19 @@ func (m *Entry) MarshalTo(dAtA []byte) (int, error) { i = encodeVarintDashboard(dAtA, i, uint64(len(m.ImageURL))) i += copy(dAtA[i:], m.ImageURL) } - if m.Kind != 0 { + if m.IsExternal { dAtA[i] = 0x28 i++ + if m.IsExternal { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i++ + } + if m.Kind != 0 { + dAtA[i] = 0x30 + i++ i = encodeVarintDashboard(dAtA, i, uint64(m.Kind)) } return i, nil @@ -332,6 +351,9 @@ func (m *Entry) Size() (n int) { if l > 0 { n += 1 + l + sovDashboard(uint64(l)) } + if m.IsExternal { + n += 2 + } if m.Kind != 0 { n += 1 + sovDashboard(uint64(m.Kind)) } @@ -578,6 +600,26 @@ func (m *Entry) Unmarshal(dAtA []byte) error { m.ImageURL = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex case 5: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field IsExternal", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDashboard + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + m.IsExternal = bool(v != 0) + case 6: if wireType != 0 { return fmt.Errorf("proto: wrong wireType = %d for field Kind", wireType) } diff --git a/pkg/dashboard/dashboard.proto b/pkg/dashboard/dashboard.proto index 2a018aba..62abaacd 100644 --- a/pkg/dashboard/dashboard.proto +++ b/pkg/dashboard/dashboard.proto @@ -31,5 +31,6 @@ message Entry { string url = 2 [(gogoproto.customname) = "URL"]; string description = 3; string image_url = 4 [(gogoproto.customname) = "ImageURL"]; - Kind kind = 5; + bool is_external = 5; + Kind kind = 6; } diff --git a/swagger.yaml b/swagger.yaml index 1f07d24a..5e83c515 100644 --- a/swagger.yaml +++ b/swagger.yaml @@ -522,6 +522,10 @@ "image_url": { "type": "string" }, + "is_external": { + "type": "boolean", + "format": "boolean" + }, "kind": { "$ref": "#/definitions/EntryKind" } diff --git a/templates/home.tmpl b/templates/home.tmpl index da638d5b..a3e1a6f0 100644 --- a/templates/home.tmpl +++ b/templates/home.tmpl @@ -1,46 +1,38 @@ {{define "fulltitle"}}Camembert au lait crew{{end}} -{{define "content"}} -Maizonn -{{end}} - - - - +{{/* +{{ block title }}{{ images | length }} trucs{{ endblock }} +{{ block subtitle }}au hasard{{ endblock }} +*/}} -{{/* -{% extends "base.html" %} -{# set page_title = 'Coucou' #} -{% set columns = 4 %} -{% set grid_size = 12 // columns %} -{% set square_size = 250 %} -{% set neige = 0 %} +{{define "content"}} +{{ $columns := 4 }} +{{ $grid_size := div 12 $columns }} +{{ $square_size := 250 }} +{{ $neige := 0 }} -{% block title %}{{ images | length }} trucs{% endblock %} -{% block subtitle %}au hasard{% endblock %} -{% block content %}
- {% for image in images %} + {{ range $entry := .dashboard.Entries }} -
{# add rotate-random after christmas #} - + - {% endfor %} + {{ end }} +

Et plein d'autres..

-{% endblock %} -*/}} +{{end}} diff --git a/views/views.go b/views/views.go index e416524f..e3c98437 100644 --- a/views/views.go +++ b/views/views.go @@ -5,12 +5,14 @@ import ( "sync" "github.com/gorilla/mux" + "ultre.me/calcbiz/api" "ultre.me/calcbiz/pkg/crew" ) type Options struct { Router *mux.Router Debug bool + Svc api.ServerServer } func Setup(opts *Options) error { @@ -75,7 +77,12 @@ type renderData map[string]interface{} func (h *handlers) homeHandler(w http.ResponseWriter, r *http.Request) { h.setDefaultHeaders(w) - data := renderData{"hello": "world"} + dashboard, err := h.opts.Svc.Dashboard(nil, &api.Void{}) + if err != nil { + h.renderError(w, r, err) + return + } + data := renderData{"dashboard": dashboard} h.render(w, r, "home.tmpl", data) }