go.chromium.org/luci@v0.0.0-20250314024836-d9a61d0730e6/tokenserver/appengine/impl/utils/service_info.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 utils
    16  
    17  import (
    18  	"context"
    19  	"fmt"
    20  
    21  	"go.chromium.org/luci/server/auth/signing"
    22  )
    23  
    24  // ServiceVersion returns a string that identifies the app and the version.
    25  //
    26  // It is put in some server responses. The function extracts this information
    27  // from the given signer.
    28  //
    29  // This function almost never returns errors. It can return an error only when
    30  // called for the first time during the process lifetime. It gets cached after
    31  // first successful return.
    32  func ServiceVersion(c context.Context, s signing.Signer) (string, error) {
    33  	inf, err := s.ServiceInfo(c) // cached
    34  	if err != nil {
    35  		return "", err
    36  	}
    37  	return fmt.Sprintf("%s/%s", inf.AppID, inf.AppVersion), nil
    38  }