File: greeter.go

package info (click to toggle)
golang-github-golang-mock 1.6.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bookworm-backports, forky, sid, trixie
  • size: 800 kB
  • sloc: sh: 58; makefile: 3
file content (31 lines) | stat: -rw-r--r-- 757 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package greeter

//go:generate mockgen -source greeter.go -destination greeter_mock_test.go -package greeter

import (
	// stdlib import
	"fmt"

	// non-matching import suffix and package name
	"github.com/golang/mock/mockgen/internal/tests/custom_package_name/client/v1"

	//  matching import suffix and package name
	"github.com/golang/mock/mockgen/internal/tests/custom_package_name/validator"
)

type InputMaker interface {
	MakeInput() client.GreetInput
}

type Greeter struct {
	InputMaker InputMaker
	Client     *client.Client
}

func (g *Greeter) Greet() (string, error) {
	in := g.InputMaker.MakeInput()
	if err := validator.Validate(in.Name); err != nil {
		return "", fmt.Errorf("validation failed: %v", err)
	}
	return g.Client.Greet(in), nil
}