<p>I learn k8s sdk source code has a question,when a method return point type,the caller can
direct use method return value without using * get the value, <a href="https://github.com/kubernetes/client-go/blob/28ccde769fc5519dd84e5512ebf303ac86ef9d7c/examples/out-of-cluster-client-configuration/main.go#L68" rel="nofollow noreferrer">the demo code</a>
<a href="https://i.stack.imgur.com/cll2C.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cll2C.png" alt="code images" /></a></p>
<p>the method defined
<a href="https://i.stack.imgur.com/i4fGG.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/i4fGG.jpg" alt="enter image description here" /></a></p>
<h2>why, the demo code,direct use pods,not *pods</h2>

fuyou001
<p>That's one of the differences between go and other (mostly older) languages in the C family. In some languages, you need to use a dedicated operator to access fields on objects that through indirection (ie pointers), in golang, the dot operator handles both.</p>
<p>In case someone stumbles across this question and doesn't know what this all means: If you had a pointer to a type like this in C:</p>
<pre><code>typedef struct pod_list {
    item items[100]; // or something
} pod_list;
</code></pre>
<p>You would need to write the following to access the <code>items</code> array:</p>
<pre><code>item * an_item = pods-&gt;items[1];
</code></pre>
<p>Or you'd need to dereference the pointer first, then access the array directly:</p>
<pre><code>item *an_item = (*pods).items[1]; // can't remember off the top of my head if the brackets are needed here though
</code></pre>
<p>Golang has an arrow operator, but it's used to write to channels:</p>
<pre><code>ch := make(chan struct{}, 1)
ch &lt;- struct{}{}
</code></pre>
<p>Or specify channel directionality when passing it as an argument:</p>
<pre><code>func doStuff(ctx context.Context, ch chan&lt;- struct{}) {
    // this function can only write to the channel
}
func doMoreStuff(ctx context.Context, ch &lt;-chan struct{}) {
    // this function can only read from the channel
}
</code></pre>
<p>When it comes to accessing fields of objects, the <code>.</code> operator handles both direct and indirect access. I had a quick look on the golang pages to see if they elaborate on this design decision, and found this line on the golang tour page about accessing struct fields:</p>
<blockquote>
<p>To access the field <code>X</code> of a struct when we have the struct pointer <code>p</code> we could write <code>(*p).X</code>. However, that notation is cumbersome, so the language permits us instead to write just <code>p.X</code>, without the explicit dereference.</p>
</blockquote>
<p>So the TL;DR is this: you <em>could</em> write <code>(*pods).Items</code> and explicitly dereference the pointer, but it's simply not needed. Having written a fair bit of C before moving to golang, I initially thought I'd prefer the explicit nature of the arrow operator, because I like knowing whether a variable is a pointer or not. Then again, after a few years, I can't say I miss the faffing around with dereferencing, arrow operators, let alone multiple levels of indirection. 99% of the time, if the code is well written, you know what is a pointer and what isn't anyway.</p>
