Пример #1
0
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
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
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
func printEncodedType(formatter cli.Formatter, encoder encoding.EncoderType) {
	e, _ := encoding.NewEncoder(encoder)
	str, _ := e.MarshalIndent(formatter.Data().Data)
	fmt.Println(str)
}