Fix README sample code errors

Closes https://github.com/tus/tusd/pull/87
This commit is contained in:
mrezai 2017-01-04 21:30:40 +01:00 committed by Marius
parent 0a8a3e7e51
commit e89661cbda
1 changed files with 9 additions and 5 deletions

View File

@ -54,14 +54,17 @@ your own Go program:
package main package main
import ( import (
"fmt"
"net/http"
"github.com/tus/tusd" "github.com/tus/tusd"
"github.com/tus/tusd/filestore" "github.com/tus/tusd/filestore"
"net/http"
) )
func main() { func main() {
// Create a new FileStore instance which is responsible for // Create a new FileStore instance which is responsible for
// storing the uploaded file on disk in the specified directory. // storing the uploaded file on disk in the specified directory.
// This path _must_ exist before tusd will store uploads in it.
// If you want to save them on a different medium, for example // If you want to save them on a different medium, for example
// a remote FTP server, you can implement your own storage backend // a remote FTP server, you can implement your own storage backend
// by implementing the tusd.DataStore interface. // by implementing the tusd.DataStore interface.
@ -79,22 +82,23 @@ func main() {
// Create a new HTTP handler for the tusd server by providing a configuration. // Create a new HTTP handler for the tusd server by providing a configuration.
// The StoreComposer property must be set to allow the handler to function. // The StoreComposer property must be set to allow the handler to function.
handler, err := tusd.NewHandler(tusd.Config{ handler, err := tusd.NewHandler(tusd.Config{
BasePath: "files/", BasePath: "/files/",
StoreComposer: composer, StoreComposer: composer,
}) })
if err != nil { if err != nil {
panic("Unable to create handler: %s", err) panic(fmt.Errorf("Unable to create handler: %s", err))
} }
// Right now, nothing has happened since we need to start the HTTP server on // Right now, nothing has happened since we need to start the HTTP server on
// our own. In the end, tusd will start listening on and accept request at // our own. In the end, tusd will start listening on and accept request at
// http://localhost:8080/files // http://localhost:8080/files
http.Handle("files/", http.StripPrefix("files/", handler)) http.Handle("/files/", http.StripPrefix("/files/", handler))
err = http.ListenAndServe(":8080", nil) err = http.ListenAndServe(":8080", nil)
if err != nil { if err != nil {
panic("Unable to listen: %s", err) panic(fmt.Errorf("Unable to listen: %s", err))
} }
} }
``` ```
Please consult the [online documentation](https://godoc.org/github.com/tus/tusd) Please consult the [online documentation](https://godoc.org/github.com/tus/tusd)