Sign inSign up

wangyanglinux/tools

By wangyanglinux

•Updated 11 months ago

工具镜像

Image
0

10K+

wangyanglinux/tools repository overview

⁠wangyanglinux/tools:randexitv1 镜像说明
⁠Dockerfile 文件
FROM alpine
ADD ./randexit /root
RUN chmod +x /root/randexit
CMD ["--sleeptime=5"]  
ENTRYPOINT ["/root/randexit"]
⁠randexit 的源码 main.go
package main

import (
	"flag"
	"fmt"
	"math/rand"
	"os"
	"time"
)

func main() {
	sleepTime := flag.Int("sleeptime", 4, "休眠时间")
	exitcode := flag.Int("exitcode", 2, "返回码")
	flag.Parse()
	sleeptimeDing := *sleepTime

	// 处理休眠逻辑
	for *sleepTime >= 0 {
		time.Sleep(time.Second * 1)
		*sleepTime--
	}

	// 产生随机返回码
	// exitcode 值为 0, 返回码为 0
	// exitcode 值为 1,返回码为 1
	// 否则随机产生返回码
	if *exitcode == 0 {
		fmt.Printf("休眠 %v 秒,返回码为 %v!\n", sleeptimeDing, 0)
		os.Exit(0)
	} else  if *exitcode == 1 {
		fmt.Printf("休眠 %v 秒,返回码为 %v!\n",sleeptimeDing, 1)
		os.Exit(1)
	} else {
		rand.Seed(time.Now().UnixNano())
		num := rand.Intn(100)
		if num >= 50 {
			fmt.Printf("休眠 %v 秒,产生的随机数为 %v,大于等于 50 ,返回码为 %v!\n",sleeptimeDing , num, 1)
			os.Exit(1)
		} else {
			fmt.Printf("休眠 %v 秒,产生的随机数为 %v,小于等于 50 ,返回码为 %v!\n",sleeptimeDing , num, 0)
			os.Exit(0)
		}
	}
}

Tag summary

Content type

Image

Digest

sha256:df4ef6b2b…

Size

12.2 MB

Last updated

11 months ago

docker pull wangyanglinux/tools:envoy-proxyprotocol