...

Source file src/github.com/google/go-containerregistry/cmd/registry/main.go

Documentation: github.com/google/go-containerregistry/cmd/registry

     1  // Copyright 2019 Google LLC All Rights Reserved.
     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  package main
    16  
    17  import (
    18  	"flag"
    19  	"fmt"
    20  	"log"
    21  	"net"
    22  	"net/http"
    23  	"time"
    24  
    25  	"github.com/google/go-containerregistry/pkg/registry"
    26  )
    27  
    28  var port = flag.Int("port", 1338, "port to run registry on")
    29  
    30  func main() {
    31  	flag.Parse()
    32  
    33  	listener, err := net.Listen("tcp", fmt.Sprintf("localhost:%d", *port))
    34  	if err != nil {
    35  		log.Fatal(err)
    36  	}
    37  	porti := listener.Addr().(*net.TCPAddr).Port
    38  	log.Printf("serving on port %d", porti)
    39  	s := &http.Server{
    40  		ReadHeaderTimeout: 5 * time.Second, // prevent slowloris, quiet linter
    41  		Handler: registry.New(
    42  			registry.WithWarning(.01, "Congratulations! You've won a lifetime's supply of free image pulls from this in-memory registry!"),
    43  		),
    44  	}
    45  	log.Fatal(s.Serve(listener))
    46  }
    47  

View as plain text