go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/logdog/common/viewer/url.go (about) 1 // Copyright 2016 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 viewer is a support library to interact with the LogDog web app and 16 // log stream viewer. 17 package viewer 18 19 import ( 20 "fmt" 21 "net/url" 22 23 "go.chromium.org/luci/logdog/common/types" 24 ) 25 26 // LogDogViewerURLTag is a special LogDog tag that is recognized by the LogDog 27 // viewer as a link back to the source of the log stream (usually a build page). 28 const LogDogViewerURLTag = "logdog.viewer_url" 29 30 // GetURL generates a LogDog app viewer URL for the specified streams. 31 // Uses the plain-text endpoint for single stream paths, and the client-side endpoint for multi-stream paths. 32 func GetURL(host string, project string, paths ...types.StreamPath) string { 33 values := make([]string, len(paths)) 34 for i, p := range paths { 35 values[i] = fmt.Sprintf("%s/%s", project, p) 36 } 37 u := url.URL{ 38 Scheme: "https", 39 Host: host, 40 } 41 if len(values) == 1 { 42 u.Path = "logs/" + values[0] 43 } else { 44 u.Path = "v/" 45 u.RawQuery = url.Values{ 46 "s": values, 47 }.Encode() 48 } 49 return u.String() 50 }