MCPcopy Create free account
hub / github.com/easyp-tech/server / NewWithConfig

Function NewWithConfig

internal/connect/api.go:66–130  ·  view source on GitHub ↗

NewWithConfig is like New but enables commit-resolution enhancements per cfg. PrewarmEnabled launches a best-effort background HEAD sweep; ProbeEnabled turns on the upstream sha probe for Download cache misses.

(
	log *slog.Logger,
	core provider,
	domain string,
	cfg CommitResolution,
	opts ...connect.HandlerOption,
)

Source from the content-addressed store, hash-verified

64// PrewarmEnabled launches a best-effort background HEAD sweep; ProbeEnabled
65// turns on the upstream sha probe for Download cache misses.
66func NewWithConfig(
67 log *slog.Logger,
68 core provider,
69 domain string,
70 cfg CommitResolution,
71 opts ...connect.HandlerOption,
72) *http.ServeMux {
73 a := &api{ //nolint:exhaustruct
74 log: log,
75 repo: core,
76 domain: domain,
77 }
78
79 mux := http.NewServeMux()
80
81 mux.Handle(v1alpha1connect.NewResolveServiceHandler(a, opts...))
82 mux.Handle(v1alpha1connect.NewRepositoryServiceHandler(a, opts...))
83 mux.Handle(v1alpha1connect.NewDownloadServiceHandler(a, opts...))
84
85 // CommitService/GraphService/DownloadService handlers for buf CLI v1.69.0+.
86 // Both v1 and v1beta1 paths are registered because buf CLI uses v1beta1
87 // paths with v1 buf.yaml config and v1 paths with v2 buf.yaml config.
88 // OwnerService is also part of the v1 API surface that buf CLI calls
89 // during `buf dep update`; without it the request falls through to the
90 // catch-all rootHandler and the client sees a text/plain response,
91 // which the buf CLI rejects with "invalid content-type: ... expecting
92 // application/proto".
93 knownOwners := buildKnownOwners(core.Repositories())
94 singleModule := buildKnownModules(core.Repositories())
95 commitHandler := &commitServiceHandler{
96 api: a,
97 commitMap: make(map[string]moduleRef),
98 infoCache: make(map[string]commitInfoCache),
99 filesMap: make(map[string][]content.File),
100 knownOwners: knownOwners,
101 singleModule: singleModule,
102 missCache: make(map[string]time.Time),
103
104 prewarmEnabled: cfg.PrewarmEnabled,
105 prewarmTimeout: cfg.PrewarmTimeout,
106 probeEnabled: cfg.ProbeEnabled,
107 probeNegativeTTL: cfg.ProbeNegativeTTL,
108 probeTimeout: cfg.ProbeTimeout,
109 probeSem: make(chan struct{}, maxConcurrentProbes),
110 }
111 if commitHandler.prewarmEnabled && commitHandler.prewarmTimeout > 0 {
112 go commitHandler.prewarmHeads()
113 }
114 if commitHandler.probeEnabled && commitHandler.probeNegativeTTL > 0 {
115 go commitHandler.sweepMisses(context.Background())
116 }
117 mux.HandleFunc("/buf.registry.module.v1.CommitService/", commitHandler.ServeHTTP)
118 mux.HandleFunc("/buf.registry.module.v1beta1.CommitService/", commitHandler.ServeHTTP)
119 mux.HandleFunc("/buf.registry.module.v1.GraphService/", commitHandler.ServeGraph)
120 mux.HandleFunc("/buf.registry.module.v1beta1.GraphService/", commitHandler.ServeGraph)
121 mux.HandleFunc("/buf.registry.module.v1.DownloadService/", commitHandler.ServeDownload)
122 mux.HandleFunc("/buf.registry.module.v1beta1.DownloadService/", commitHandler.ServeDownload)
123 mux.HandleFunc("/buf.registry.module.v1.ModuleService/", commitHandler.ServeGetModules)

Callers 3

mainFunction · 0.92
NewFunction · 0.85
testMuxWithConfigFunction · 0.85

Calls 8

prewarmHeadsMethod · 0.95
sweepMissesMethod · 0.95
NewResolveServiceHandlerFunction · 0.92
buildKnownOwnersFunction · 0.85
buildKnownModulesFunction · 0.85
RepositoriesMethod · 0.65

Tested by 1

testMuxWithConfigFunction · 0.68