示例#1
0
文件: client.go 项目: ContainX/depcon
func (h *HttpClient) convert(r *Request, content string) error {
	um, _ := encoding.NewEncoder(encoding.JSON)
	if r.encodingType != 0 {
		um, _ = encoding.NewEncoder(r.encodingType)
	}
	um.UnMarshalStr(content, r.result)
	return nil

}
示例#2
0
文件: group.go 项目: ContainX/depcon
func (c *MarathonClient) ParseGroupFromString(r io.Reader, et encoding.EncoderType, opts *CreateOptions) (*Group, error) {

	options := initCreateOptions(opts)

	var encoder encoding.Encoder
	var err error

	encoder, err = encoding.NewEncoder(et)
	if err != nil {
		return nil, err
	}

	parsed, missing := envsubst.SubstFileTokens(r, options.EnvParams)

	if opts.ErrorOnMissingParams && missing {
		return nil, ErrorAppParamsMissing
	}

	if opts.DryRun {
		fmt.Printf("Create Group :: DryRun :: Template Output\n\n%s", parsed)
		os.Exit(0)
	}

	group := new(Group)
	err = encoder.UnMarshalStr(parsed, &group)
	if err != nil {
		return nil, err
	}
	return group, nil
}
示例#3
0
文件: client.go 项目: ContainX/depcon
func (h *HttpClient) convertBody(data interface{}) string {
	if data == nil {
		return ""
	}
	encoder, _ := encoding.NewEncoder(encoding.JSON)
	body, _ := encoder.Marshal(data)
	return body
}
示例#4
0
func LoadTemplateContext(filename string) (*TemplateContext, error) {
	ctx, err := os.Open(filename)
	if err != nil {
		return nil, err
	}

	encoder, err := encoding.NewEncoder(encoding.JSON)
	if err != nil {
		return nil, err
	}

	result := &TemplateContext{Environments: make(map[string]*TemplateEnvironment)}

	if err := encoder.UnMarshal(ctx, result); err != nil {
		return nil, err
	}
	return result, nil
}
示例#5
0
文件: format.go 项目: ContainX/depcon
func printEncodedType(formatter cli.Formatter, encoder encoding.EncoderType) {
	e, _ := encoding.NewEncoder(encoder)
	str, _ := e.MarshalIndent(formatter.Data().Data)
	fmt.Println(str)
}