go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/luciexe/legacy/annotee/link_generator.go (about)

     1  // Copyright 2017 The LUCI Authors.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package annotee
    16  
    17  import (
    18  	"go.chromium.org/luci/logdog/common/types"
    19  	"go.chromium.org/luci/logdog/common/viewer"
    20  )
    21  
    22  // LinkGenerator generates links for a given log stream.
    23  type LinkGenerator interface {
    24  	// GetLink returns a link for the specified aggregate streams.
    25  	//
    26  	// If no link could be generated, GetLink may return an empty string.
    27  	GetLink(name ...types.StreamName) string
    28  }
    29  
    30  // CoordinatorLinkGenerator is a LinkGenerator implementation
    31  type CoordinatorLinkGenerator struct {
    32  	Host    string
    33  	Project string
    34  	Prefix  types.StreamName
    35  }
    36  
    37  // CanGenerateLinks returns true if g is sufficiently configured to generate
    38  // LogDog Coordinator links.
    39  func (g *CoordinatorLinkGenerator) CanGenerateLinks() bool {
    40  	return (g.Host != "" && g.Prefix != "")
    41  }
    42  
    43  // GetLink implements LinkGenerator.
    44  func (g *CoordinatorLinkGenerator) GetLink(names ...types.StreamName) string {
    45  	paths := make([]types.StreamPath, len(names))
    46  	for i, name := range names {
    47  		paths[i] = g.Prefix.AsPathPrefix(name)
    48  	}
    49  	return viewer.GetURL(g.Host, g.Project, paths...)
    50  }