Skip to content

fragmenta/router

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

router

A router which allows pattern matching, routes, redirects, filters and provides a handler interface. This router is now deprecated, use fragmenta mux instead as in the example fragmenta/cms app, this requires changing the handler signature to one closer to the net/http standard library, and using a simpler context object.

Usage

Setup the router

	// Routing
	router, err := router.New(server.Logger, server)
	if err != nil {
		server.Fatalf("Error creating router %s", err)
	}

Add a route with named parameters, matching a regexp, and a method if necessary

	r.Add("/tags/{id:[0-9]+}/destroy", tagactions.HandleDestroy).Post()

ContextHandler interface

The router handlers accept a context (which wraps Writer and Request, and provides some other functions), and return an error for easier error handling. The error may contain status codes and other details of the error for reporting in development environments.

	// Setup server
	server, err := server.New()
	if err != nil {
		fmt.Printf("Error creating server %s", err)
		return
	}

	// Write to log 
	server.Logf("#info Starting server in %s mode on port %d", server.Mode(), server.Port())

	// Start the server
	err = server.Start()
	if err != nil {
		server.Fatalf("Error starting server %s", err)
	}

About

[Deprecated] A router linking URIs to handlers

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages