github.com/thiagoyeds/go-cloud@v0.26.0/server/driver/driver.go (about) 1 // Copyright 2018 The Go Cloud Development Kit Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // https://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 // Package driver defines an interface for custom HTTP listeners. 16 // Application code should use package server. 17 package driver // import "gocloud.dev/server/driver" 18 19 import ( 20 "context" 21 "net/http" 22 ) 23 24 // Server dispatches requests to an http.Handler. 25 type Server interface { 26 // ListenAndServe listens on the TCP network address addr and then 27 // calls Serve with handler to handle requests on incoming connections. 28 // The addr argument will be a non-empty string specifying "host:port". 29 // The http.Handler will always be non-nil. 30 // Drivers must block until serving is done (or 31 // return an error if serving can't occur for some reason), serve 32 // requests to the given http.Handler, and be interruptable by Shutdown. 33 // Drivers should use the given address if they serve using TCP directly. 34 ListenAndServe(addr string, h http.Handler) error 35 36 // Shutdown gracefully shuts down the server without interrupting 37 // any active connections. If the provided context expires before 38 // the shutdown is complete, Shutdown returns the context's error, 39 // otherwise it returns any error returned from closing the Server's 40 // underlying Listener(s). 41 Shutdown(ctx context.Context) error 42 } 43 44 // TLSServer is an optional interface for Server drivers, that adds support 45 // for serving TLS. 46 type TLSServer interface { 47 // ListenAndServeTLS is similar to Server.ListenAndServe, but should 48 // serve using TLS. 49 // See http://go/godoc/net/http/#Server.ListenAndServeTLS. 50 ListenAndServeTLS(addr, certFile, keyFile string, h http.Handler) error 51 }