title: local Method call results in: undeclared name: [name]
body: <h2>Summary: Local Method call (inside same file) results in: <code>[govet] undeclared name: QueryPart [Error]</code></h2>
  <h2>Edit: Please see summary of mistakes and correction at bottom of post.</h2>
  <p>I'm very new to Go, and am trying to build some simple Hyperledger Fabric chaincode.</p>
  <p>In the following code, I have a method <code>QueryPart</code> which I can call successfully.  I wanted to see if I could write another method <code>QueryPartSpecial</code> to call the original <code>QueryPart</code> method (and then do some other stuff), but I'm getting a fatal error: <code>[govet] undeclared name: QueryPart [Error]</code></p>
  <pre><code>  231 //QueryPart: queries a single part from the ledger (with provided partID)
    232 func (s *SmartContract) QueryPart(ctx contractapi.TransactionContextInterface, partID string) (*Part, error) {
    233   assetJSON, err := ctx.GetStub().GetState(partID)
    234   if err != nil {
    235     return nil, fmt.Errorf(&quot;failed to read from world state: %v&quot;, err)
    236   }
    237   if assetJSON == nil {
    238     return nil, fmt.Errorf(&quot;the asset %s does not exist&quot;, partID)
    239   }
    240   
    241   var part Part
    242   err = json.Unmarshal(assetJSON, &amp;part)
    243   if err != nil {
    244     return nil, err
    245   }
    246 
    247   return &amp;part, nil
    248 }
    249 
    250 //QueryPartSpecial: calls QueryPart and does some other experimental stuff on it
    251 func QueryPartSpecial(partID string) (*Part, error) {
  ✘ 252   part, err := QueryPart(partID)
    253   //placeholder for some other code
    254   return part, err
    255 } 
  
  </code></pre>
  <p>Why would I get this error since func <code>QueryPart</code> is clearly declared above?</p>
  <p>Note: This question appears very similar to the following questions:<br />
  <a href="https://stackoverflow.com/questions/25171409/function-in-same-package-undefined">Function in same package undefined</a><br>
  <a href="https://stackoverflow.com/questions/46645061/go-undefined-function-in-same-package">Go: undefined function in same package</a></p>
  <p>However, the main difference from these other questions is that my two functions reside inside in the same [file].go.</p>
  <p>Note 2: the error I am getting is a linting error, but is also preventing me from compiling/installing the chaincode.</p>
  <h2>Edit: What I did wrong and what I learned:</h2>
  <p>The error I received was due to problems with the <code>QueryPartSpecial</code> method, rather than the <code>QueryPart</code> method.</p>
  <p>As a new learner to Go, I made several mistakes:</p>
  <ol>
  <li>Confusing <a href="https://www.geeksforgeeks.org/methods-in-golang/" rel="nofollow noreferrer">methods and functions</a>.
  (In my original post, I referred to both methods as functions.)</li>
  <li>Incorrectly constructing <code>QueryPartSpecial</code>: As Lucas pointed out, I did not include any object in <code>QueryPartSpecial</code>.  By modifying this function to a method with a pointer receiver of SmartContract, I could provide an object when calling <code>QueryPart</code>.</li>
  <li>Incorrectly calling the method <code>QueryPart</code>: Since methods operate on a object, they should be called on an object.</li>
  </ol>
  <p>This is my corrected code (which is functional without an error returned):</p>
  <pre><code>255 //QueryPartSpecial: calls QueryPart and does some other experimental stuff on it
  256 func (s *SmartContract) QueryPartSpecial(ctx contractapi.TransactionContextInterface, partID string) (*Part, error) {
  257   part, err := s.QueryPart(ctx,partID)
  258   //placeholder for some other code
  259   return part, err
  260 } 
  </code></pre>
  <p>(Thank you, Lucas, Adrian, and Volker for your help and for steering me in the right direction.)</p>