1 /* 2 Copyright 2016 The Kubernetes Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package fakegitserver 18 19 import ( 20 "io" 21 "net/http" 22 23 "github.com/spf13/cobra" 24 ) 25 26 // CmdFakeGitServer is used by agnhost Cobra. 27 var CmdFakeGitServer = &cobra.Command{ 28 Use: "fake-gitserver", 29 Short: "Fakes a git server", 30 Long: `When doing "git clone http://localhost:8000", you will clone an empty git repo named "localhost" on local. 31 You can also use "git clone http://localhost:8000 my-repo-name" to rename that repo.`, 32 Args: cobra.MaximumNArgs(0), 33 Run: main, 34 } 35 36 func hello(w http.ResponseWriter, r *http.Request) { 37 io.WriteString(w, "I am a fake git server") 38 39 } 40 41 // When doing `git clone localhost:8000`, you will clone an empty git repo named "8000" on local. 42 // You can also use `git clone localhost:8000 my-repo-name` to rename that repo. 43 func main(cmd *cobra.Command, args []string) { 44 http.HandleFunc("/", hello) 45 http.ListenAndServe(":8000", nil) 46 } 47