vanity

vanity - A tiny server for golang vanity redirects
Log | Files | Refs | README | LICENSE

server.go (1237B)


      1 /*
      2    Copyright 2021 Mark Wilkerson
      3 
      4    This program is free software: you can redistribute it and/or modify
      5     it under the terms of the GNU General Public License as published by
      6     the Free Software Foundation, either version 3 of the License.
      7 
      8     This program is distributed in the hope that it will be useful,
      9     but WITHOUT ANY WARRANTY; without even the implied warranty of
     10     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     11     GNU General Public License for more details.
     12 
     13     You should have received a copy of the GNU General Public License
     14     along with this program.  If not, see <https://www.gnu.org/licenses/>
     15 */
     16 
     17 package main
     18 
     19 import (
     20 	"fmt"
     21 	"log"
     22 	"net/http"
     23 	"time"
     24 )
     25 
     26 // populated at build time from ldflags
     27 var VERSION string
     28 
     29 func main() {
     30 
     31 	opts := Init()
     32 
     33 	server := &http.Server{
     34 		Addr:         fmt.Sprintf("%s:%d", opts.BindAddr, opts.Port),
     35 		ReadTimeout:  500 * time.Millisecond,
     36 		WriteTimeout: 500 * time.Millisecond,
     37 		Handler:      handler(opts),
     38 	}
     39 
     40 	log.Printf("vanity v%s listening on %s:%d", VERSION, opts.BindAddr, opts.Port)
     41 
     42 	if opts.SSLCert != "" {
     43 
     44 		log.Fatal(server.ListenAndServeTLS(opts.SSLCert, opts.SSLKeyFile))
     45 
     46 	} else {
     47 
     48 		log.Fatal(server.ListenAndServe())
     49 
     50 	}
     51 
     52 }