github.com/linuxboot/fiano@v1.2.0/pkg/uefi/visitor.go (about) 1 // Copyright 2018 the LinuxBoot Authors. All rights reserved 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package uefi 6 7 // Visitor represents an operation which can be applied to the Firmware. 8 // Typically, the Visit function contains a type switch for the different 9 // firmware types and a default case. For example: 10 // 11 // func (v *Example) Visit(f uefi.Firmware) error { 12 // switch f := f.(type) { 13 // 14 // case *uefi.File: 15 // fmt.Println("f is a file") 16 // return f.ApplyChildren(v) // Children are recursed over 17 // 18 // case *uefi.Section: 19 // fmt.Println("f is a section") 20 // return nil // Children are not visited 21 // 22 // default: 23 // // The default action is to recurse over children. 24 // return f.ApplyChildren(v) 25 // } 26 // } 27 type Visitor interface { 28 // Run wraps Visit. Additionally, it performs some setup and teardown 29 // tasks. As a consumer of the visitor, Run is typically the function 30 // you should call. 31 Run(Firmware) error 32 33 // Visit applies the visitor to the Firmware and (usually) recurses 34 // over the children. 35 Visit(Firmware) error 36 }