example_server

package
v0.77.0-dev-1 Latest Latest
Warning

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

Go to latest
Published: May 28, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Cmd = &cobra.Command{
	Use:   "server",
	Short: "Server with random data endpoints",
	Args:  cobra.NoArgs,
	Run: func(c *cobra.Command, args []string) {
		portStr := strconv.Itoa(FlagPort)
		hostname, _ := os.Hostname()
		http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
			fmt.Fprintf(w, "[slu "+version.Version+"] Server with random data endpoints! %s %s \n", hostname, portStr)
			fmt.Printf("RemoteAddr=%s\n", r.RemoteAddr)
		})

		http.HandleFunc("/v1/slu_random_password", func(w http.ResponseWriter, r *http.Request) {
			password, err := random_utils.RandomPassword()
			if err != nil {
				http.Error(w, err.Error(), http.StatusInternalServerError)
				return
			}
			fmt.Fprintf(w, "%s\n", password)
		})

		fmt.Println("[slu " + version.Version + "] Server started on 0.0.0.0:" + portStr + ", see http://127.0.0.1:" + portStr)
		http.ListenAndServe(":"+portStr, nil)
	},
}
View Source
var FlagPort int

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