long_response

package
v0.79.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 16, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Cmd = &cobra.Command{
	Use:     "long-response",
	Short:   "Server with long response time",
	Aliases: []string{"long", "lr", "lore"},
	Args:    cobra.NoArgs,
	Run: func(c *cobra.Command, args []string) {
		http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
			hostname, _ := os.Hostname()
			sleepTime, err := strconv.Atoi(strings.ReplaceAll(r.URL.Path, "/", ""))
			if err != nil {
				fmt.Println(err)
				fmt.Println("set sleep time to 0s (default)")
			}
			time.Sleep(time.Duration(sleepTime) * time.Second)
			fmt.Fprintf(w, "[slu-debug-server] Response after %ds! %s \n", sleepTime, hostname)
		})
		fmt.Println("Server started on 0.0.0.0:8000, see http://127.0.0.1:8000")
		http.ListenAndServe(":8000", nil)
	},
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL