mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-08 21:08:10 -05:00
* Implement static analysis to prevent panics * Add nopanic to nogo * Fix violations and add exclusions Fix violations and add exclusions for all * Changelog fragment * Use pass.Report instead of pass.Reportf * Remove strings.ToLower for checking init method name * Add exclusion for herumi init * Move api/client/beacon template function to init and its own file * Fix nopanic testcase
35 lines
897 B
Go
35 lines
897 B
Go
package beacon
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
"text/template"
|
|
)
|
|
|
|
type templateFn func(StateOrBlockId) string
|
|
|
|
var getBlockRootTpl templateFn
|
|
var getForkTpl templateFn
|
|
|
|
func init() {
|
|
// idTemplate is used to create template functions that can interpolate StateOrBlockId values.
|
|
idTemplate := func(ts string) func(StateOrBlockId) string {
|
|
t := template.Must(template.New("").Parse(ts))
|
|
f := func(id StateOrBlockId) string {
|
|
b := bytes.NewBuffer(nil)
|
|
err := t.Execute(b, struct{ Id string }{Id: string(id)})
|
|
if err != nil {
|
|
panic(fmt.Sprintf("invalid idTemplate: %s", ts))
|
|
}
|
|
return b.String()
|
|
}
|
|
// run the template to ensure that it is valid
|
|
// this should happen load time (using package scoped vars) to ensure runtime errors aren't possible
|
|
_ = f(IdGenesis)
|
|
return f
|
|
}
|
|
|
|
getBlockRootTpl = idTemplate(getBlockRootPath)
|
|
getForkTpl = idTemplate(getForkForStatePath)
|
|
}
|