Home Download Docs Code Community
     1	/*
     2	Copyright 2015 The Perkeep Authors
     3	
     4	Licensed under the Apache License, Version 2.0 (the "License");
     5	you may not use this file except in compliance with the License.
     6	You may obtain a copy of the License at
     7	
     8	     http://www.apache.org/licenses/LICENSE-2.0
     9	
    10	Unless required by applicable law or agreed to in writing, software
    11	distributed under the License is distributed on an "AS IS" BASIS,
    12	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13	See the License for the specific language governing permissions and
    14	limitations under the License.
    15	*/
    16	
    17	// Package env detects what sort of environment Perkeep is running in.
    18	package env // import "perkeep.org/pkg/env"
    19	
    20	import (
    21		"os"
    22		"strconv"
    23		"sync"
    24	
    25		"cloud.google.com/go/compute/metadata"
    26	)
    27	
    28	// IsDebug reports whether this is a debug environment.
    29	func IsDebug() bool {
    30		return isDebug
    31	}
    32	
    33	// DebugUploads reports whether this is a debug environment for uploads.
    34	func DebugUploads() bool {
    35		return isDebugUploads
    36	}
    37	
    38	// IsDev reports whether this is a development server environment (devcam server).
    39	func IsDev() bool {
    40		return isDev
    41	}
    42	
    43	// OnGCE reports whether this process is running in a Google Compute
    44	// Engine (GCE) environment.  This only returns true if the
    45	// "camlistore-config-dir" instance metadata value is defined.
    46	// Instances running in custom configs on GCE will be unaffected.
    47	func OnGCE() bool {
    48		gceOnce.Do(detectGCE)
    49		return isGCE
    50	}
    51	
    52	var (
    53		gceOnce sync.Once
    54		isGCE   bool
    55	)
    56	
    57	func detectGCE() {
    58		if !metadata.OnGCE() {
    59			return
    60		}
    61		v, _ := metadata.InstanceAttributeValue("camlistore-config-dir")
    62		isGCE = v != ""
    63	}
    64	
    65	var (
    66		isDev             = os.Getenv("CAMLI_DEV_CAMLI_ROOT") != ""
    67		isDebug, _        = strconv.ParseBool(os.Getenv("CAMLI_DEBUG"))
    68		isDebugUploads, _ = strconv.ParseBool(os.Getenv("CAMLI_DEBUG_UPLOADS"))
    69	)
Website layout inspired by memcached.
Content by the authors.