github.com/v2fly/v2ray-core/v5@v5.16.2-0.20240507031116-8191faa6e095/main/commands/all/engineering/encodedataurl.go (about)

     1  package engineering
     2  
     3  import (
     4  	"flag"
     5  	"io"
     6  	"os"
     7  
     8  	"github.com/vincent-petithory/dataurl"
     9  
    10  	"github.com/v2fly/v2ray-core/v5/main/commands/base"
    11  )
    12  
    13  var cmdEncodeDataURLContentType *string
    14  
    15  var cmdEncodeDataURL = &base.Command{
    16  	UsageLine: "{{.Exec}} engineering encodeDataURL",
    17  	Flag: func() flag.FlagSet {
    18  		fs := flag.NewFlagSet("", flag.ExitOnError)
    19  		cmdEncodeDataURLContentType = fs.String("type", "application/vnd.v2ray.subscription-singular", "")
    20  		return *fs
    21  	}(),
    22  	Run: func(cmd *base.Command, args []string) {
    23  		cmd.Flag.Parse(args)
    24  
    25  		content, err := io.ReadAll(os.Stdin)
    26  		if err != nil {
    27  			base.Fatalf("%s", err)
    28  		}
    29  		dataURL := dataurl.New(content, *cmdEncodeDataURLContentType)
    30  		dataURL.WriteTo(os.Stdout)
    31  	},
    32  }