github.com/demonoid81/moby@v0.0.0-20200517203328-62dd8e17c460/testutil/fixtures/plugin/basic/basic.go (about)

     1  package main
     2  
     3  import (
     4  	"fmt"
     5  	"net"
     6  	"net/http"
     7  	"os"
     8  	"path/filepath"
     9  )
    10  
    11  func main() {
    12  	p, err := filepath.Abs(filepath.Join("run", "docker", "plugins"))
    13  	if err != nil {
    14  		panic(err)
    15  	}
    16  	if err := os.MkdirAll(p, 0755); err != nil {
    17  		panic(err)
    18  	}
    19  	l, err := net.Listen("unix", filepath.Join(p, "basic.sock"))
    20  	if err != nil {
    21  		panic(err)
    22  	}
    23  
    24  	mux := http.NewServeMux()
    25  	server := http.Server{
    26  		Addr:    l.Addr().String(),
    27  		Handler: http.NewServeMux(),
    28  	}
    29  	mux.HandleFunc("/Plugin.Activate", func(w http.ResponseWriter, r *http.Request) {
    30  		w.Header().Set("Content-Type", "application/vnd.docker.plugins.v1.1+json")
    31  		fmt.Println(w, `{"Implements": ["dummy"]}`)
    32  	})
    33  	server.Serve(l)
    34  }