Commits

Miki Tebeka  committed 41c3bc5

License and more

  • Participants
  • Parent commits ac1894a

Comments (0)

Files changed (3)

+Copyright (c) 2012, Miki Tebeka <miki.tebeka@gmail.com>
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of
+this software and associated documentation files (the "Software"), to deal in
+the Software without restriction, including without limitation the rights to
+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+the Software, and to permit persons to whom the Software is furnished to do so,
+subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
     
 
 `nrsc.Get(path string) Resource`
-
     Will return a resource interface (or `nil` if not found) (see resource interface below).
     This allows you more control on how to serve.
 
 `func Open() io.Reader`
     Returns a reader to resource data
 
-`func Length() int`
+`func Size() int64`
     Returns resource size (to be used with `Content-Length` HTTP header).
 
-`func Type() string`
+`func MimeType() string`
     Returns mime type (to be used with `Content-Type` HTTP header).
 
-`func Time() time.Time`
+`func ModTime() time.Time`
     Returns modification time (to be used with `Last-Modified` HTTP header).
+
+
+Example Code
+------------
+::
+
+    package main
+
+    import (
+            "fmt"
+            "net/http"
+            "os"
+
+            "./nrsc"
+    )
+
+    func indexHandler(w http.ResponseWriter, req *http.Request) {
+            fmt.Fprintf(w, "Hello World\n")
+    }
+
+    func main() {
+            nrsc.Handle("/static/")
+            http.HandleFunc("/", indexHandler)
+            if err := http.ListenAndServe(":8080", nil); err != nil {
+                    fmt.Fprintf(os.Stderr, "error: %s\n", err)
+                    os.Exit(1)
+            }
+    }
+
+Contact
+=======
+https://bitbucket.org/tebeka/nrsc
     
-
-Status
-======
-Current status of the code is "playing". Nothing really written. There's an
-example implementation in the `playground` directory and a web server in `hw.go`.
+License
+=======
+MIT (see `LICENSE.txt`)
 	"strings"
 )
 
+const (
+	version = "0.1.0"
+	outdir  = "nrsc"
+)
+
 var ignoredDirs = map[string]bool{
 	".svn": true,
 	".hg":  true,
 	info os.FileInfo
 }
 
+// iterfiles iterats of directory tree, returns a channel with files to process
 func iterfiles(root string) chan *File {
 	out := make(chan *File)
 
 	return out
 }
 
+// writeResource write resource code to out
 func writeResource(prefix int, file *File, out io.Writer) error {
 	data, err := ioutil.ReadFile(file.path)
 	if err != nil {
 	return nil
 }
 
+// die prints error and exists the program with exit status 1
 func die(format string, args ...interface{}) {
 	message := fmt.Sprintf(format, args...)
 	fmt.Fprintf(os.Stderr, "error: %s\n", message)
 	os.Exit(1)
 }
 
+// dirExists return true if path exists and is a directory
 func dirExists(path string) bool {
 	info, err := os.Stat(path)
 	if err == nil {
 	return false
 }
 
+// writeResources writes the go code for the resources file
 func writeResources(root string, out io.Writer) error {
 	prefix := len(root)
 	if root[len(root)-1] != '/' {
 
 func main() {
 	var root string
-	outdir := "nrsc"
+	var showVersion bool
 
 	flag.StringVar(&root, "root", "", "root direcotry")
+	flag.BoolVar(&showVersion, "version", false, "show version and exit")
 	flag.Parse()
 
+	if showVersion {
+		fmt.Printf("nrsc %s\n", version)
+		os.Exit(0)
+	}
+
 	if len(root) == 0 {
 		die("<root> is required")
 	}