@@ -70,18 +70,6 @@ func ResourceType() RunResourceType {
7070 return LocalResource
7171}
7272
73- // Name returns a preferred name for the currently running Cloud Run service or
74- // job. This will be either the service or job name or simply 'local'.
75- func Name () string {
76- if ResourceType () == ServiceResource {
77- return ServiceName ()
78- }
79- if ResourceType () == JobResource {
80- return JobName ()
81- }
82- return "local"
83- }
84-
8573// ID returns the unique instance ID of the Cloud Run instance serving the
8674// running job or service by referring to the metadata server.
8775//
@@ -99,6 +87,18 @@ func InstanceID() string {
9987 return this .instanceID
10088}
10189
90+ // Name returns a preferred name for the currently running Cloud Run service or
91+ // job. This will be either the service or job name or simply 'local'.
92+ func Name () string {
93+ if ResourceType () == ServiceResource {
94+ return ServiceName ()
95+ }
96+ if ResourceType () == JobResource {
97+ return JobName ()
98+ }
99+ return "local"
100+ }
101+
102102// ServiceName returns the name of the currently running Cloud Run service by
103103// looking up the `K_SERVICE` environment variable.
104104//
@@ -160,6 +160,22 @@ func Execution() string {
160160 return this .jobExecution
161161}
162162
163+ // Port looks up and returns the configured service `$PORT` for
164+ // this Cloud Run service.
165+ //
166+ // If the current process does not seem to be hosted on Cloud Run, it will
167+ // return the default value `8080`.
168+ func Port () string {
169+ if this .servicePort != "" {
170+ return this .servicePort
171+ }
172+ this .servicePort = os .Getenv ("PORT" )
173+ if this .servicePort == "" {
174+ this .servicePort = "8080"
175+ }
176+ return this .servicePort
177+ }
178+
163179// ProjectID attempts to resolve the alphanumeric Google Cloud project ID that
164180// is hosting the current Cloud Run instance.
165181//
@@ -299,22 +315,6 @@ func AddOIDCHeader(r *http.Request, audience string) *http.Request {
299315 return r
300316}
301317
302- // Port looks up and returns the configured service `$PORT` for
303- // this Cloud Run service.
304- //
305- // If the current process does not seem to be hosted on Cloud Run, it will
306- // return the default value `8080`.
307- func Port () string {
308- if this .servicePort != "" {
309- return this .servicePort
310- }
311- this .servicePort = os .Getenv ("PORT" )
312- if this .servicePort == "" {
313- this .servicePort = "8080"
314- }
315- return this .servicePort
316- }
317-
318318// TaskIndex looks up and returns the current task index for the running
319319// Cloud Run job.
320320//
@@ -733,7 +733,7 @@ func loadKNativeService() error {
733733 }
734734
735735 url := fmt .Sprintf (
736- "https://%s-run.googleapis.com/apis/serving.knative.dev/v1/namespaces/%s/routes /%s" ,
736+ "https://%s-run.googleapis.com/apis/serving.knative.dev/v1/namespaces/%s/services /%s" ,
737737 Region (),
738738 ProjectID (),
739739 ServiceName (),
0 commit comments