code: def find_struct(
      file: str, gotype: str
  ) -> Tuple[List[FieldSpec], List[UnionSpec]]:
      """
      Open a file and find a struct definition for a given name.
  
      If the given name is not a struct, it returns empty lists.
  
      This function uses regex to read the golang source code... hacky, but it works.
      """
      field_spec = []  # type: List[FieldSpec]
      union_spec = []  # type: List[UnionSpec]
      with open(file) as f:
          state = "pre"
          for lineno, line in enumerate(f.readlines()):
              if state == "pre":
                  if line.startswith(f"type {gotype} struct"):
                      state = "fields"
                  elif line.startswith(f"type {gotype}"):
                      # Non-struct type; return empty field_spec and union_spec.
                      return [], []
              elif state == "fields":
                  if line.strip() == "}":
                      # No more fields
                      return field_spec, union_spec
                  if line.strip() == "":
                      # No field on this line
                      continue
                  if line.startswith("\t//"):
                      # comment line
                      continue
  
                  # Union fields.
                  match = re.match(
                      "\t([\\S]+)\\s+([\\S]+)\\s+`union.*", line
                  )
                  if match is not None:
                      field, type = match[1], match[2]
                      union_spec.append((field, type))
                      continue
  
                  # Normal fields: capture the field name, the type, and the json tag.
                  match = re.match(
                      '\t([\\S]+)\\s+([\\S]+)\\s+`json:"([^,"]+)', line
                  )
                  if match is not None:
                      field, type, tag = match[1], match[2], match[3]
                      # store the field name and the type
                      field_spec.append((field, type, tag))
                      continue
  
                  raise AssertionError(
                      f"unsure how to handle line {lineno}: '{line.rstrip()}'"
                  )
  
      # We should have exited when we saw the "}" line.
      raise AssertionError(
          f"failed to find struct definition for {gotype} in {file}"
      )
  
imports: import argparse
  import json
  import os
  import re
  import sys
  from typing import List, Optional, Tuple
label_desc: Use image node_id 6 for calling a global function with example usage: find_struct(file, gotype) and returns: list,  list, field_spec,  union_spec