Initial commit: Go 1.23 release state
This commit is contained in:
10
test/fixedbugs/issue59709.dir/aconfig.go
Normal file
10
test/fixedbugs/issue59709.dir/aconfig.go
Normal file
@@ -0,0 +1,10 @@
|
||||
// Copyright 2023 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package aconfig
|
||||
|
||||
type Config struct {
|
||||
name string
|
||||
blah int
|
||||
}
|
||||
27
test/fixedbugs/issue59709.dir/bresource.go
Normal file
27
test/fixedbugs/issue59709.dir/bresource.go
Normal file
@@ -0,0 +1,27 @@
|
||||
// Copyright 2023 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package bresource
|
||||
|
||||
type Resource[T any] struct {
|
||||
name string
|
||||
initializer Initializer[T]
|
||||
cfg ResConfig
|
||||
value T
|
||||
}
|
||||
|
||||
func Should[T any](r *Resource[T], e error) bool {
|
||||
return r.cfg.ShouldRetry(e)
|
||||
}
|
||||
|
||||
type ResConfig struct {
|
||||
ShouldRetry func(error) bool
|
||||
TearDown func()
|
||||
}
|
||||
|
||||
type Initializer[T any] func(*int) (T, error)
|
||||
|
||||
func New[T any](name string, f Initializer[T], cfg ResConfig) *Resource[T] {
|
||||
return &Resource[T]{name: name, initializer: f, cfg: cfg}
|
||||
}
|
||||
37
test/fixedbugs/issue59709.dir/cmem.go
Normal file
37
test/fixedbugs/issue59709.dir/cmem.go
Normal file
@@ -0,0 +1,37 @@
|
||||
// Copyright 2023 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package cmem
|
||||
|
||||
import (
|
||||
"./aconfig"
|
||||
"./bresource"
|
||||
)
|
||||
|
||||
type MemT *int
|
||||
|
||||
var G int
|
||||
|
||||
type memResource struct {
|
||||
x *int
|
||||
}
|
||||
|
||||
func (m *memResource) initialize(*int) (res *int, err error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (m *memResource) teardown() {
|
||||
}
|
||||
|
||||
func NewResource(cfg *aconfig.Config) *bresource.Resource[*int] {
|
||||
res := &memResource{
|
||||
x: &G,
|
||||
}
|
||||
|
||||
return bresource.New("Mem", res.initialize, bresource.ResConfig{
|
||||
// We always would want to retry the Memcache initialization.
|
||||
ShouldRetry: func(error) bool { return true },
|
||||
TearDown: res.teardown,
|
||||
})
|
||||
}
|
||||
39
test/fixedbugs/issue59709.dir/dcache.go
Normal file
39
test/fixedbugs/issue59709.dir/dcache.go
Normal file
@@ -0,0 +1,39 @@
|
||||
// Copyright 2023 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package dcache
|
||||
|
||||
import (
|
||||
"./aconfig"
|
||||
"./bresource"
|
||||
"./cmem"
|
||||
)
|
||||
|
||||
type Module struct {
|
||||
cfg *aconfig.Config
|
||||
err error
|
||||
last any
|
||||
}
|
||||
|
||||
//go:noinline
|
||||
func TD() {
|
||||
}
|
||||
|
||||
func (m *Module) Configure(x string) error {
|
||||
if m.err != nil {
|
||||
return m.err
|
||||
}
|
||||
res := cmem.NewResource(m.cfg)
|
||||
m.last = res
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Module) Blurb(x string, e error) bool {
|
||||
res, ok := m.last.(*bresource.Resource[*int])
|
||||
if !ok {
|
||||
panic("bad")
|
||||
}
|
||||
return bresource.Should(res, e)
|
||||
}
|
||||
17
test/fixedbugs/issue59709.dir/main.go
Normal file
17
test/fixedbugs/issue59709.dir/main.go
Normal file
@@ -0,0 +1,17 @@
|
||||
// Copyright 2023 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"./dcache"
|
||||
)
|
||||
|
||||
func main() {
|
||||
var m dcache.Module
|
||||
m.Configure("x")
|
||||
m.Configure("y")
|
||||
var e error
|
||||
m.Blurb("x", e)
|
||||
}
|
||||
Reference in New Issue
Block a user