Kubernetes Learning Notes-----The Go language Structtag

Source: Internet
Author: User
Tags k8s
This is a creation in Article, where the information may have evolved or changed.

Read the Kubernetes source code, read the Https://github.com/kubernetes/kubernetes/blob/master/pkg/apis/extensions/types.go K8s type, when you encounter such a piece of code,

Represents a scaling request for a resource.type the scale struct {unversioned. Typemeta ' JSON: ", inline" '//Standard object metadata; More Info:http://releases.k8s.io/head/docs/devel/api-conventions.md#metadata.api.objectmeta ' JSON: ' metadata, Omitempty "//defines the behavior of the scale. More info:http://releases.k8s.io/head/docs/devel/api-conventions.md#spec-and-status. Spec scalespec ' json: ' spec,omitempty '//current status of the scale. More info:http://releases.k8s.io/head/docs/devel/api-conventions.md#spec-and-status. Read-only.status scalestatus ' JSON: "Status,omitempty" '}

And then the back of the "inside of the JSON string, I don't understand


This is the structtag of the Go language.


What's 1 for?

If you want to manually configure the corresponding relationship between the members of the struct and the JSON field, you can label the members when you define the structure body:

With Omitempty, if the field is nil or 0 values (the number 0, the string "", the empty array [], and so on), then the wrapped JSON result will not have this fields.


2 How to use AH? http://blog.csdn.net/tiaotiaoyly/article/details/38942311 Click to open link

Type Message struct {Name string ' JSON: ' msg_name '///Msg_namebody string ' JSON for JSON: ' body,omitempty '///if empty, ignore Field time Int64 ' JSON: "-" '///Direct Ignore field}var m = message{name: "Alice", Body: ", Time:1294706395881547000,}data, er r: = json. Marshal (m) if err! = Nil {fmt. Printf (Err. Error ()) return}fmt. PRINTLN (String data) output:{"Msg_name": "Alice"}


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.