summary refs log tree commit diff stats
path: root/main.go
diff options
context:
space:
mode:
authorBen Morrison <ben@gbmor.dev>2019-05-11 04:08:05 -0400
committerBen Morrison <ben@gbmor.dev>2019-05-11 04:08:05 -0400
commitc87acad59c4436554e60ab14870b77e49046c84a (patch)
tree0170c7e8d0767c53f3017ecbf49ed2ef35c3ae45 /main.go
parentd62c82f30506baa430fb7e3e117f007cfa66ac13 (diff)
downloadgetwtxt-c87acad59c4436554e60ab14870b77e49046c84a.tar.gz
more graceful routing of http requests
Diffstat (limited to 'main.go')
-rw-r--r--main.go31
1 files changed, 23 insertions, 8 deletions
diff --git a/main.go b/main.go
index d8a0614..9cc1337 100644
--- a/main.go
+++ b/main.go
@@ -3,6 +3,7 @@ package main
 import (
 	"log"
 	"net/http"
+	"time"
 
 	"github.com/gorilla/handlers"
 	"github.com/gorilla/mux"
@@ -10,17 +11,31 @@ import (
 
 const getwtxt = "0.1"
 
+var closelog = make(chan bool)
+
 func main() {
 	log.Printf("getwtxt " + getwtxt + "\n")
 
-	serv := mux.NewRouter()
+	index := mux.NewRouter()
+	api := index.PathPrefix("/api").Subrouter()
+
+	index.HandleFunc("/", indexHandler)
+	api.HandleFunc("/", apiBaseHandler)
+	api.HandleFunc("/{format:(?:plain)}", apiFormatHandler)
+	api.HandleFunc("/{format:(?:plain)}/{endpoint:(?:mentions|users|tweets)}", apiEndpointHandler)
+	api.HandleFunc("/{format:(?:plain)}/tags", apiTagsBaseHandler)
+	api.HandleFunc("/{format:(?:plain)}/tags/{tags:[a-zA-Z0-9]+}", apiTagsHandler)
 
-	serv.HandleFunc("/", indexHandler)
-	serv.HandleFunc("/{api:(?:api|api/)}", apiBaseHandler)
-	serv.HandleFunc("/api/{format:(?:plain|plain/)}", apiFormatHandler)
-	serv.HandleFunc("/api/{format:(?:plain)}/{endpoint:(?:mentions|mentions/|users|users/|tweets|tweets/)}", apiEndpointHandler)
-	serv.HandleFunc("/api/{format:(?:plain)}/tags/{tags:[a-zA-Z0-9]+}", apiTagsHandler)
-	serv.HandleFunc("/api/{format:(?:plain)}/{tagpathfixer:(?:tags|tags/)}", apiTagsBaseHandler)
+	server := &http.Server{
+		Handler:      handlers.CompressHandler(index),
+		Addr:         ":9001",
+		WriteTimeout: 15 * time.Second,
+		ReadTimeout:  15 * time.Second,
+	}
 
-	log.Fatalln(http.ListenAndServe(":8080", handlers.CompressHandler(serv)))
+	err := server.ListenAndServe()
+	if err != nil {
+		log.Printf("%v\n", err)
+	}
+	closelog <- true
 }
436989b618eb58c4a6a71'>01a8d44 ^
650a1fb ^
1076f2b
650a1fb ^
1076f2b
650a1fb ^
1076f2b

650a1fb ^
1076f2b
eff4478 ^
1076f2b
7b5638f ^

98c6a92 ^
98c6a92 ^

0b5dcf2 ^
7b5638f ^
6d209b9 ^

98c6a92 ^
7b5638f ^
1076f2b

dc5c070 ^

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
                            
                            
                                                                  

 

            
                                                     



            

                                                               
 
                                                                   



                      


                                                                             
 
           
           
                                                                  
 
            
 
                                                             

                                                        
                              
 
                                                        
 

                                                                
 

              
                                                        
               

            
 
 

             

                                                              
dwm - dynamic window manager
============================
dwm is an extremely fast, small, and dynamic window manager for X.


Requirements
------------
In order to build dwm you need the Xlib header files.


Installation
------------
Edit config.mk to match your local setup (dwm is installed into
the /usr/local namespace by default).

Afterwards enter the following command to build and install dwm (if
necessary as root):

    make clean install

If you are going to use the default bluegray color scheme it is highly
recommended to also install the bluegray files shipped in the dextra package.


Running dwm
-----------
Add the following line to your .xinitrc to start dwm using startx:

    exec dwm

In order to connect dwm to a specific display, make sure that
the DISPLAY environment variable is set correctly, e.g.:

    DISPLAY=foo.bar:1 exec dwm

(This will start dwm on display :1 of the host foo.bar.)

In order to display status info in the bar, you can do something
like this in your .xinitrc:

    while true
    do
        xsetroot -name "`date` `uptime | sed 's/.*,//'`"
        sleep 1
    done &
    exec dwm


Configuration
-------------
The configuration of dwm is done by creating a custom config.h
and (re)compiling the source code.