1 // Copyright 2015 CoreOS, Inc. 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 // http://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 //go:build ignore 16 // +build ignore 17 18 package main 19 20 import ( 21 "io" 22 "net/http" 23 24 "github.com/coreos/go-systemd/v22/activation" 25 ) 26 27 func HelloServer(w http.ResponseWriter, req *http.Request) { 28 io.WriteString(w, "hello socket activated world!\n") 29 } 30 31 func main() { 32 listeners, err := activation.Listeners() 33 if err != nil { 34 panic(err) 35 } 36 37 if len(listeners) != 1 { 38 panic("Unexpected number of socket activation fds") 39 } 40 41 http.HandleFunc("/", HelloServer) 42 http.Serve(listeners[0], nil) 43 } 44