Skip to content

Latest commit

 

History

History

lazyaction

lazyaction

Variables

var (
    ErrNotFound      = errors.New("not found")
    ErrNotAuthorized = errors.New("not authorized")
)
var Actions = lazysupport.NewStringSet("Index", "Show", "Create", "Update", "Destroy", "New", "Edit")
var Store = sessions.NewCookieStore([]byte("//TODO: make this random and persistant"))

Types

type Action

type Action struct { ... }

func (*Action) String

func (r *Action) String() string

type Context

type Context struct { ... }

func (*Context) GetHeader

func (c *Context) GetHeader(h string) string

func (*Context) Redirect

func (c *Context) Redirect(url string, status int)

func (*Context) Render

func (c *Context) Render(data ...any)

func (*Context) Write

func (c *Context) Write(data []byte)

func (*Context) WriteString

func (c *Context) WriteString(data string)

type Middleware interface { ... }

type Request

type Request struct { ... }

func (*Request) GetParam

func (r *Request) GetParam(name string) string

type Resource struct { ... }

func (*Resource) Actions

func (r *Resource) Actions() []*Action

func (r *Resource) addSubResources() {

for _, sr := range r.SubResources {
	resource := NewResource(sr)
	for _, action := range resource.ResourceActions {
		a := *action
		segments := make([]string, len(r.Prefix))
		copy(segments, r.Prefix)
		segments = append(segments, r.ParamName)

		a.Path = "/" + strings.Join(segments, "/") + a.Path
		a.RouteName = r.Singular + "_" + a.ResourceName
		if a.ActionName != "" {
			a.RouteName = a.ActionName + "_" + a.RouteName
		}

		for i := range a.ParamsPosition {
			a.ParamsPosition[i] += len(segments)
		}

		a.ParamsPosition = append([]int{len(segments) - 1}, a.ParamsPosition...)

		r.ResourceActions = append(r.ResourceActions, &a)
	}
}

}

type ResourceOptions struct { ... }

type ResponseWriter struct { ... }

func (ResponseWriter) WriteString

func (w ResponseWriter) WriteString(s string) (int, error)

type Router

type Router interface { ... }

type Routes

type Routes struct { ... }

func (*Routes) Resource

func (r *Routes) Resource(target any, options ...*ResourceOptions)

Resource adds a resource to the router

The resource name is extracted from the struct name minus the Controller suffix. If the struct is called Controller it will use the package name.

Given a struct called UserController, the follwing methods will generate the following routes:

  • Index() => GET /users
  • New() => GET /users/new
  • Create() => POST /users
  • Show() => GET /users/:id
  • Edit() => GET /users/:id/edit
  • Update() => PUT /users/:id
  • Destroy() => DELETE /users/:id

Custom actions can be added to the resource by combining the verb and if it belongs to a Member.

  • Popular() => GET /users/popular
  • MemberComments() => GET /users/:id/comments
  • PutMemberSuspend() => PUT /users/:id/suspend

Resource internally calls Route to add the routes to the router.

func (*Routes) Route

func (r *Routes) Route(arguments ...any)

Route adds routes to the router

Router.Route("/", func()string{return "Hello"}) // If verb is omited it is assumed is a GET
Router.Route("POST", "/users", func() string{ return "User created!"})  // Verb can be added as a string

func (*Routes) ServeHTTP

func (r *Routes) ServeHTTP(w http.ResponseWriter, req *http.Request)

func (*Routes) String

func (r *Routes) String() string

type Session

type Session struct { ... }

func (*Session) AddFlash

func (s *Session) AddFlash(val any, vars ...string)

func (*Session) Delete

func (s *Session) Delete(key string)

func (*Session) Flashes

func (s *Session) Flashes(vars ...string) []any

func (*Session) Get

func (s *Session) Get(key string) any

func (*Session) GetError

func (s *Session) GetError() string

func (*Session) GetFlash

func (s *Session) GetFlash(key string) string

func (*Session) GetNotice

func (s *Session) GetNotice() string

func (*Session) GetString

func (s *Session) GetString(key string) string

func (*Session) Set

func (s *Session) Set(key string, val any)

func (*Session) SetError

func (s *Session) SetError(err error)

func (*Session) SetFlash

func (s *Session) SetFlash(key string, val string)

func (*Session) SetNotice

func (s *Session) SetNotice(notice string)

func (*Session) SetString

func (s *Session) SetString(key, val string)


Readme created from Go doc with goreadme