From ad85ecc1da8bf7abfd040cb1a7bf98da2c9caf9e Mon Sep 17 00:00:00 2001 From: Zack Scholl Date: Tue, 29 Mar 2016 16:09:21 -0400 Subject: [PATCH] Restructured helptext, readme Former-commit-id: db3a0d5d035ee1e4ca2a918268d2422994826f06 [formerly c8c26fe5a5f17530f760e580d3120733b9f05aec] [formerly 787c25f6e9f7b298d598e4002f8e7d5f3f82d68f [formerly 1fb3282c1ca8cf597602ca2c6203534573dd4e8d]] Former-commit-id: 49b0da7945773cce3c07edb0b1d7a160fea30472 [formerly bdb9d8e6ed376c8216a09b86453c19c326f66f15] Former-commit-id: 846154396ecd0adedeebe9fa05b3ae8abed803e1 --- README.md | 96 ++++++++++--------------------------------------------- main.go | 28 +++++++++++----- 2 files changed, 37 insertions(+), 87 deletions(-) diff --git a/README.md b/README.md index 2b4d818..598a28e 100644 --- a/README.md +++ b/README.md @@ -44,13 +44,13 @@ This is a self-contained notepad webserver that makes sharing easy and _fast_. T
-**Coding**. There is CodeMirror support for many languages. Just use an extension for your document and then you'll be able to edit/view your code in a simple and easy way. +**Syntax highlighting**. There is CodeMirror support for many languages. Just use an extension (e.g. .py, .md, .txt, .js, ...) for your document and then you'll be able to edit/view your code in a simple and easy way. -![Security and encryption baked in.](NEED GIF) +![Coding syntax is provided if you use an extension](NEED GIF)
-**CLI tools**. Want to upload/download from the command line? Its super easy. Upload/download files like this: +**CLI tools**. Want to upload/download from the command line? Its super easy. Upload/download files using `curl` with a simple command: ```bash $ echo "Hello, world!" > hi.txt $ curl -L --upload-file hi.txt cowyo.com @@ -58,7 +58,7 @@ $ curl -L --upload-file hi.txt cowyo.com $ curl -L cowyo.com/test.txt Hello, world! ``` -or just skip the file-creation step and let cowyo figure out a name for you: +or just skip the file-creation step and let `cowyo` figure out a name for you: ```bash $ echo "Wow, so easy" | curl -L --upload-file "-" cowyo.com File uploaded to http://cowyo.com/CautiousCommonLoon @@ -67,13 +67,7 @@ $ curl -L cowyo.com/CautiousCommonLoon ```
-**Content Delivery**. Want to write some CSS/JS that you want to load somewhere? No problem. Just use the extension `/raw` with optional versioning (e.g. `/raw?version=1`). So you if you make a javascript file, `cowyo.com/myscript.js`, then you can include your script using: -```html - - -``` - -
+**Content Delivery**. Want use a script on your own domain? Just use the extension `/raw` with optional versioning (e.g. `/raw?version=1`). `cowyo` will serve these files with a wildcard Access-Control-Allow-Origin so they will work anywhere. Check out a live example [on this JSFiddle](https://jsfiddle.net/g87w7kt0/). **Keyboard Shortcuts**. Quickly transition between Edit/View/List by using `Ctl+Shift+E` to Edit, `Ctl+Shift+Z` to View, and `Ctl+Shift+L` to Listify. @@ -85,80 +79,24 @@ $ curl -L cowyo.com/CautiousCommonLoon # Install -First [install Go](https://golang.org/doc/install). Then continue. - -## To access locally... - -Then, if you want to host on your local network just do: +If you haven't done so, first [install Go](https://golang.org/doc/install). ``` -git clone https://github.com/schollz/cowyo.git -cd cowyo -make -./cowyo -p :8001 LOCALIPADDRESS +$ git clone https://github.com/schollz/cowyo.git +$ cd cowyo +$ go get ./... +$ go build +$ ./cowyo +-------------------------- +cowyo (version Y) is up and running on http://SOMEADDRESS:8003 +Admin key: VRSgtuVpkrwtWrfphsooOYeErzdbVHHqecMcqcbkLFNFNPwakH +-------------------------- ``` -and then goto the address `http://LOCALIPADDRESS:8001/` - -## To access from anywhere... - -For this you need to forward port 80 and [get a DNS for your external address](https://www.duckdns.org/). I recommend using `NGINX` as middleware, as it will do caching of the static files for you. - -```bash -sudo apt-get install nginx -``` - -There is an example `NGINX` block in `install/`. If you want to use SSL instead, follow the instructions in `letsencrypt/README.md`. To automatically install, on Raspberry Pi / Ubuntu / Debian system use: - -``` -git clone https://github.com/schollz/cowyo.git -cd cowyo -nano Makefile <--- EDIT this Makefile to include YOUR EXTERNAL ADDRESS -make && sudo make install -``` - -Now the program starts and stops with - -``` -sudo /etc/init.d/cowyo start|stop|restart -``` - -Edit your crontab (`sudo crontab -e`) to start on boot: - -``` -@reboot /etc/init.d/cowyo start -``` - -# Usage - -``` -$ cowyo --help -cowyo: A Websocket Wiki and Kind Of A List Application -run this to start the server and then visit localhost at the port you specify -(see parameters). -Example: 'cowyo localhost' -Example: 'cowyo -p :8080 localhost:8080' -Example: 'cowyo -db /var/lib/cowyo/db.bolt localhost:8003' -Example: 'cowyo -p :8080 -crt ssl/server.crt -key ssl/server.key localhost:8080' -Options: - -a string - key to access admin priveleges (default no admin priveleges) - -crt string - location of ssl crt - -db string - location of database file (default "/home/mu/cowyo/data.db") - -httptest.serve string - if non-empty, httptest.NewServer serves on this address and blocks - -key string - location of ssl key - -p string - port to bind (default ":8003") -``` - -If you set the admin flag, `-a` you can access a list of all the current files by going to `/ls/WhateverYouSetTheFlagTo`. +Now open your browser to `http://SOMEADDRESS:8003` to see your cowyo! For more information type `./cowyo --help`. # Contact -If you'd like help, go ahead and clone and send a pull request. If you find a bug, please submit [an issue](https://github.com/schollz/cowyo/issues). Any other comments, questions or anything at all, just tweet me @zack_118 +If you'd like help or you find a bug, please submit [an issue](https://github.com/schollz/cowyo/issues). Any other comments, questions or anything at all, just tweet me @zack_118 # Contributors Thanks to [tscholl2](https://github.com/tscholl2) and [sjsafranek](https://github.com/sjsafranek). diff --git a/main.go b/main.go index 6663546..31fcd09 100644 --- a/main.go +++ b/main.go @@ -35,6 +35,10 @@ var RuntimeArgs struct { } var VersionNum string +func init() { + gin.SetMode(gin.ReleaseMode) +} + func main() { VersionNum = "0.95" // _, executableFile, _, _ := runtime.Caller(0) // get full path of this file @@ -42,20 +46,25 @@ func main() { databaseFile := path.Join(cwd, "data.db") flag.StringVar(&RuntimeArgs.Port, "p", ":8003", "port to bind") flag.StringVar(&RuntimeArgs.DatabaseLocation, "db", databaseFile, "location of database file") - flag.StringVar(&RuntimeArgs.AdminKey, "a", RandStringBytesMaskImprSrc(50), "key to access admin priveleges") - flag.StringVar(&RuntimeArgs.ServerCRT, "crt", "", "location of ssl crt") - flag.StringVar(&RuntimeArgs.ServerKey, "key", "", "location of ssl key") + flag.StringVar(&RuntimeArgs.AdminKey, "a", "", "key to access admin priveleges") + flag.StringVar(&RuntimeArgs.ServerCRT, "crt", "", "location of SSL certificate") + flag.StringVar(&RuntimeArgs.ServerKey, "key", "", "location of SSL key") flag.StringVar(&RuntimeArgs.WikiName, "w", "cowyo", "custom name for wiki") - flag.BoolVar(&RuntimeArgs.ForceWss, "e", false, "force encrypted sockets") + flag.BoolVar(&RuntimeArgs.ForceWss, "e", false, "force encrypted sockets (use if using Caddy auto HTTPS)") dumpDataset := flag.Bool("dump", false, "flag to dump all data to 'dump' directory") flag.CommandLine.Usage = func() { - fmt.Println(`cowyo (version ` + VersionNum + `): A Websocket Wiki and Kind Of A List Application -run this to start the server and then visit localhost at the port you specify -(see parameters). + fmt.Println(`cowyo (version ` + VersionNum + `) + +Usage: cowyo [options] [address] + +If address is not provided then cowyo +will determine the best internal IP address. + +Example: 'cowyo' Example: 'cowyo yourserver.com' Example: 'cowyo -p :8080 localhost:8080' -Example: 'cowyo -db /var/lib/cowyo/db.bolt localhost:8003' Example: 'cowyo -p :8080 -crt ssl/server.crt -key ssl/server.key localhost:8080' + Options:`) flag.CommandLine.PrintDefaults() } @@ -73,6 +82,9 @@ Options:`) } RuntimeArgs.SourcePath = cwd + if len(RuntimeArgs.AdminKey) == 0 { + RuntimeArgs.AdminKey = RandStringBytesMaskImprSrc(50) + } // create programdata bucket Open(RuntimeArgs.DatabaseLocation)