Skip to content
This repository has been archived by the owner on May 11, 2022. It is now read-only.

Commit

Permalink
fix #113: store request context
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilsk committed Oct 16, 2018
1 parent 0c2069c commit 85c3f0e
Show file tree
Hide file tree
Showing 16 changed files with 521 additions and 328 deletions.
7 changes: 3 additions & 4 deletions env/docker/db/truncate.sql
@@ -1,5 +1,4 @@
TRUNCATE TABLE "link" RESTART IDENTITY RESTRICT;
TRUNCATE TABLE "schema" RESTART IDENTITY RESTRICT;
TRUNCATE TABLE "template" RESTART IDENTITY RESTRICT;
TRUNCATE TABLE "input" RESTART IDENTITY RESTRICT;
TRUNCATE TABLE "event" RESTART IDENTITY RESTRICT;
TRUNCATE TABLE "input" RESTART IDENTITY RESTRICT;
TRUNCATE TABLE "template" RESTART IDENTITY RESTRICT;
TRUNCATE TABLE "schema" RESTART IDENTITY RESTRICT;
11 changes: 5 additions & 6 deletions env/test/fixtures/demo.sql
Expand Up @@ -5,14 +5,13 @@ DECLARE demoAccount "account"."id"%TYPE := '10000000-2000-4000-8000-1600000000
DECLARE form "schema"."id"%TYPE := '10000000-2000-4000-8000-160000000004';
DECLARE html "template"."id"%TYPE := '10000000-2000-4000-8000-160000000005';
BEGIN
TRUNCATE TABLE "account" RESTART IDENTITY RESTRICT;
TRUNCATE TABLE "event" RESTART IDENTITY RESTRICT;
TRUNCATE TABLE "input" RESTART IDENTITY RESTRICT;
TRUNCATE TABLE "template" RESTART IDENTITY RESTRICT;
TRUNCATE TABLE "schema" RESTART IDENTITY RESTRICT;
TRUNCATE TABLE "token" RESTART IDENTITY RESTRICT;
TRUNCATE TABLE "user" RESTART IDENTITY RESTRICT;
TRUNCATE TABLE "link" RESTART IDENTITY RESTRICT;
TRUNCATE TABLE "schema" RESTART IDENTITY RESTRICT;
TRUNCATE TABLE "template" RESTART IDENTITY RESTRICT;
TRUNCATE TABLE "input" RESTART IDENTITY RESTRICT;
TRUNCATE TABLE "event" RESTART IDENTITY RESTRICT;
TRUNCATE TABLE "account" RESTART IDENTITY RESTRICT;

INSERT INTO "account" ("id", "name") VALUES (demoAccount, 'Demo Account');

Expand Down
2 changes: 1 addition & 1 deletion main_test.go
Expand Up @@ -20,7 +20,7 @@ import (
var (
_ grpc.ProtectedStorage = storage.Must()
_ router.Server = server.New(config.ServerConfig{}, nil)
_ server.Service = service.New(config.ServiceConfig{}, nil, nil)
_ server.Service = service.New(config.ServiceConfig{TemplateDir: "static/templates"}, nil, nil)
_ service.Storage = storage.Must()
_ service.Tracker = storage.Must()
)
Expand Down
20 changes: 8 additions & 12 deletions pkg/domain/input.go
Expand Up @@ -19,14 +19,10 @@ const (
)

const (
// RedirectKey TODO issue#173
RedirectKey = "_redirect"
// ResourceKey TODO issue#173
ResourceKey = "_resource"
// TemplateKey TODO issue#173
TemplateKey = "_template"
// TimeoutKey TODO issue#173
TimeoutKey = "_timeout"
redirectKey = "_redirect"
resourceKey = "_resource"
templateKey = "_template"
timeoutKey = "_timeout"
)

// Input represents an element of an HTML form.
Expand All @@ -49,7 +45,7 @@ type InputData url.Values

// Redirect TODO issue#173
func (d InputData) Redirect(fallback ...string) string {
value := url.Values(d).Get(RedirectKey)
value := url.Values(d).Get(redirectKey)
if value == "" {
for _, value = range fallback {
if value != "" {
Expand All @@ -62,12 +58,12 @@ func (d InputData) Redirect(fallback ...string) string {

// Resource TODO issue#173
func (d InputData) Resource() ID {
return ID(url.Values(d).Get(ResourceKey))
return ID(url.Values(d).Get(resourceKey))
}

// Template TODO issue#173
func (d InputData) Template() *ID {
var id = ID(url.Values(d).Get(TemplateKey))
var id = ID(url.Values(d).Get(templateKey))
if id.IsValid() {
return &id
}
Expand All @@ -76,7 +72,7 @@ func (d InputData) Template() *ID {

// Timeout TODO issue#173
func (d InputData) Timeout() time.Duration {
timeout, err := time.ParseDuration(url.Values(d).Get(TimeoutKey))
timeout, err := time.ParseDuration(url.Values(d).Get(timeoutKey))
if err != nil {
return 30 * time.Second
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/server/grpc/common.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 20 additions & 18 deletions pkg/server/grpc/event.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 85c3f0e

Please sign in to comment.