1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- // The Isomorphic Go Project
- // Copyright (c) Wirecog, LLC. All rights reserved.
- // Use of this source code is governed by a BSD-style
- // license, which can be found in the LICENSE file.
-
- package isokit
-
- import "github.com/gopherjs/gopherjs/js"
-
- type OperatingDetails struct {
- Environment int
- Runtime int
- }
-
- const (
- ServerEnvironment = iota
- WebBrowserEnvironment
- )
-
- const (
- GoRuntime = iota
- JSRuntime
- )
-
- var (
- operatingEnvironment int
- operatingRuntime int
- )
-
- func isJSRuntime() bool {
- return js.Global != nil
- }
-
- func isGoRuntime() bool {
- return !isJSRuntime()
- }
-
- func isWebBrowserEnvironment() bool {
- return isJSRuntime() && js.Global.Get("document") != js.Undefined
- }
-
- func isServerEnvironment() bool {
-
- if isGoRuntime() == true {
- return true
- } else if isJSRuntime() == true {
- return !isWebBrowserEnvironment()
- } else {
- return true
- }
-
- }
-
- func OperatingEnvironment() int {
- return operatingEnvironment
- }
-
- func OperatingRuntime() int {
- return operatingRuntime
- }
-
- func initializeOperatingDetails() {
-
- if isJSRuntime() == true {
- operatingRuntime = WebBrowserEnvironment
- }
-
- if isGoRuntime() == true {
- operatingRuntime = GoRuntime
- }
-
- if isServerEnvironment() == true {
- operatingEnvironment = ServerEnvironment
- }
-
- if isWebBrowserEnvironment() == true {
- operatingEnvironment = WebBrowserEnvironment
- }
-
- }
-
- func init() {
-
- initializeOperatingDetails()
-
- }
|