Browse Source

Drop Go <1.8 support

DarthSim 6 years ago
parent
commit
83948d0126
8 changed files with 37 additions and 70 deletions
  1. 2 2
      .travis.yml
  2. 0 9
      keepalive.go
  3. 0 7
      keepalive_old.go
  4. 2 21
      main.go
  5. 1 1
      process.go
  6. 32 0
      server.go
  7. 0 19
      shutdown.go
  8. 0 11
      shutdown_old.go

+ 2 - 2
.travis.yml

@@ -1,9 +1,9 @@
 language: go
 go:
-  - 1.6
-  - 1.7
   - 1.8
   - 1.9
+  - 1.10
+  - 1.11
   - tip
 env:
   - VIPS_VERSION=8.4.6

+ 0 - 9
keepalive.go

@@ -1,9 +0,0 @@
-// +build go1.7
-
-package main
-
-import "runtime"
-
-func keepAlive(i interface{}) {
-	runtime.KeepAlive(i)
-}

+ 0 - 7
keepalive_old.go

@@ -1,7 +0,0 @@
-// +build !go1.7
-
-package main
-
-func keepAlive(i interface{}) {
-	// Dummy function. Do nothing
-}

+ 2 - 21
main.go

@@ -1,15 +1,10 @@
 package main
 
 import (
-	"log"
-	"net"
-	"net/http"
 	"os"
 	"os/signal"
 	"runtime/debug"
 	"time"
-
-	"golang.org/x/net/netutil"
 )
 
 const version = "1.1.7"
@@ -22,27 +17,13 @@ func main() {
 		}
 	}()
 
-	l, err := net.Listen("tcp", conf.Bind)
-	if err != nil {
-		log.Fatal(err)
-	}
-
-	s := &http.Server{
-		Handler:        newHTTPHandler(),
-		ReadTimeout:    time.Duration(conf.ReadTimeout) * time.Second,
-		MaxHeaderBytes: 1 << 20,
-	}
+	s := startServer()
 
 	stop := make(chan os.Signal, 1)
 	signal.Notify(stop, os.Interrupt, os.Kill)
 
-	go func() {
-		log.Printf("Starting server at %s\n", conf.Bind)
-		log.Fatal(s.Serve(netutil.LimitListener(l, conf.MaxClients)))
-	}()
-
 	<-stop
 
-	shutdownVips()
 	shutdownServer(s)
+	shutdownVips()
 }

+ 1 - 1
process.go

@@ -248,7 +248,7 @@ func calcCrop(width, height int, po processingOptions) (left, top int) {
 
 func processImage(data []byte, imgtype imageType, po processingOptions, t *timer) ([]byte, error) {
 	defer C.vips_cleanup()
-	defer keepAlive(data)
+	defer runtime.KeepAlive(data)
 
 	if po.Gravity == SMART && !vipsSupportSmartcrop {
 		return nil, errors.New("Smart crop is not supported by used version of libvips")

+ 32 - 0
server.go

@@ -3,11 +3,13 @@ package main
 import (
 	"bytes"
 	"compress/gzip"
+	"context"
 	"crypto/subtle"
 	"encoding/base64"
 	"errors"
 	"fmt"
 	"log"
+	"net"
 	"net/http"
 	"net/url"
 	"strconv"
@@ -15,6 +17,7 @@ import (
 	"time"
 
 	nanoid "github.com/matoous/go-nanoid"
+	"golang.org/x/net/netutil"
 )
 
 var mimes = map[imageType]string{
@@ -31,6 +34,35 @@ func newHTTPHandler() *httpHandler {
 	return &httpHandler{make(chan struct{}, conf.Concurrency)}
 }
 
+func startServer() *http.Server {
+	l, err := net.Listen("tcp", conf.Bind)
+	if err != nil {
+		log.Fatal(err)
+	}
+
+	s := &http.Server{
+		Handler:        newHTTPHandler(),
+		ReadTimeout:    time.Duration(conf.ReadTimeout) * time.Second,
+		MaxHeaderBytes: 1 << 20,
+	}
+
+	go func() {
+		log.Printf("Starting server at %s\n", conf.Bind)
+		log.Fatal(s.Serve(netutil.LimitListener(l, conf.MaxClients)))
+	}()
+
+	return s
+}
+
+func shutdownServer(s *http.Server) {
+	log.Println("Shutting down the server...")
+
+	ctx, close := context.WithTimeout(context.Background(), 5*time.Second)
+	defer close()
+
+	s.Shutdown(ctx)
+}
+
 func parsePath(r *http.Request) (string, processingOptions, error) {
 	var po processingOptions
 	var err error

+ 0 - 19
shutdown.go

@@ -1,19 +0,0 @@
-// +build go1.8
-
-package main
-
-import (
-	"context"
-	"log"
-	"net/http"
-	"time"
-)
-
-func shutdownServer(s *http.Server) {
-	log.Println("Shutting down the server...")
-
-	ctx, close := context.WithTimeout(context.Background(), 5*time.Second)
-	defer close()
-
-	s.Shutdown(ctx)
-}

+ 0 - 11
shutdown_old.go

@@ -1,11 +0,0 @@
-// +build !go1.8
-
-package main
-
-import (
-	"net/http"
-)
-
-func shutdownServer(_ *http.Server) {
-	// Nothing we can do here
-}