Skip to content

Commit

Permalink
Added golint
Browse files Browse the repository at this point in the history
  • Loading branch information
petaki committed Feb 25, 2021
1 parent f062910 commit cb14e44
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 3 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,13 @@ jobs:
with:
go-version: 1.15

- name: Install dependencies
run: |
go version
go get -u golang.org/x/lint/golint
- name: Lint
run: golint ./...

- name: Test
run: go test -v ./...
3 changes: 3 additions & 0 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@ package inertia

type contextKey string

// ContextKeyProps key.
const ContextKeyProps = contextKey("props")

// ContextKeyViewData key.
const ContextKeyViewData = contextKey("viewData")
5 changes: 4 additions & 1 deletion errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package inertia
import "errors"

var (
ErrInvalidContextProps = errors.New("inertia: could not convert context props to map")
// ErrInvalidContextProps error.
ErrInvalidContextProps = errors.New("inertia: could not convert context props to map")

// ErrInvalidContextViewData error.
ErrInvalidContextViewData = errors.New("inertia: could not convert context view data to map")
)
9 changes: 8 additions & 1 deletion inertia.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"strings"
)

// Inertia type.
type Inertia struct {
url string
rootTemplate string
Expand All @@ -17,6 +18,7 @@ type Inertia struct {
sharedFuncMap template.FuncMap
}

// New function.
func New(url, rootTemplate, version string) *Inertia {
i := new(Inertia)
i.url = url
Expand All @@ -28,14 +30,17 @@ func New(url, rootTemplate, version string) *Inertia {
return i
}

// Share function.
func (i *Inertia) Share(key string, value interface{}) {
i.sharedProps[key] = value
}

// ShareFunc function.
func (i *Inertia) ShareFunc(key string, value interface{}) {
i.sharedFuncMap[key] = value
}

// WithProp function.
func (i *Inertia) WithProp(ctx context.Context, key string, value interface{}) context.Context {
contextProps := ctx.Value(ContextKeyProps)

Expand All @@ -53,6 +58,7 @@ func (i *Inertia) WithProp(ctx context.Context, key string, value interface{}) c
})
}

// WithViewData function.
func (i *Inertia) WithViewData(ctx context.Context, key string, value interface{}) context.Context {
contextViewData := ctx.Value(ContextKeyViewData)

Expand All @@ -70,6 +76,7 @@ func (i *Inertia) WithViewData(ctx context.Context, key string, value interface{
})
}

// Render function.
func (i *Inertia) Render(w http.ResponseWriter, r *http.Request, component string, props map[string]interface{}) error {
only := make(map[string]string)
partial := r.Header.Get("X-Inertia-Partial-Data")
Expand All @@ -83,7 +90,7 @@ func (i *Inertia) Render(w http.ResponseWriter, r *http.Request, component strin
page := &Page{
Component: component,
Props: make(map[string]interface{}),
Url: r.RequestURI,
URL: r.RequestURI,
Version: i.version,
}

Expand Down
1 change: 1 addition & 0 deletions middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package inertia

import "net/http"

// Middleware function.
func (i *Inertia) Middleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Header.Get("X-Inertia") == "" {
Expand Down
3 changes: 2 additions & 1 deletion page.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package inertia

// Page type.
type Page struct {
Component string `json:"component"`
Props map[string]interface{} `json:"props"`
Url string `json:"url"`
URL string `json:"url"`
Version string `json:"version"`
}

0 comments on commit cb14e44

Please sign in to comment.