<commit_before>package memsize

import (
	"fmt"
	"reflect"
)

type address uintptr

const invalidAddr = address(0)

func (a address) valid() bool {
	return a != 0
}

func (a address) addOffset(off uintptr) address {
	if !a.valid() {
		return invalidAddr
	}
	return a + address(off)
}

type typCache map[reflect.Type]typInfo

type typInfo struct {
	isPointer bool
	needScan  bool
}

func (tc *typCache) isPointer(typ reflect.Type) bool {
	return tc.info(typ).isPointer
}

func (tc *typCache) needScan(typ reflect.Type) bool {
	return tc.info(typ).needScan
}

func (tc *typCache) info(typ reflect.Type) typInfo {
	if info, ok := (*tc)[typ]; ok {
		return info
	}
	info := tc.makeInfo(typ)
	(*tc)[typ] = info
	return info
}

func (tc *typCache) makeInfo(typ reflect.Type) typInfo {
	var ti typInfo
	ti.isPointer = isPointer(typ)
	ti.needScan = ti.isPointer
	k := typ.Kind()
	if k == reflect.Array {
		ti.needScan = tc.needScan(typ.Elem())
	} else if k >= reflect.Chan && k <= reflect.Struct {
		ti.needScan = true
	}
	return ti
}

func isPointer(typ reflect.Type) bool {
	k := typ.Kind()
	switch {
	case k <= reflect.Complex128:
		return false
	case k == reflect.Array:
		return false
	case k >= reflect.Chan && k <= reflect.String:
		return true
	case k == reflect.Struct || k == reflect.UnsafePointer:
		return false
	default:
		unhandledKind(k)
		return false
	}
}

func unhandledKind(k reflect.Kind) {
	panic("unhandled kind " + k.String())
}

func humanSize(bytes uintptr) string {
	switch {
	case bytes < 1024:
		return fmt.Sprintf("%d B", bytes)
	case bytes < 1024*1024:
		return fmt.Sprintf("%.3f KB", float64(bytes)/1024)
	default:
		return fmt.Sprintf("%.3f MB", float64(bytes)/1024/1024)
	}
}
<commit_msg>memsize: document address type<commit_after>package memsize

import (
	"fmt"
	"reflect"
)

// address is a memory location.
//
// Code dealing with uintptr is oblivious to the zero address.
// Code dealing with address is not: it treats the zero address
// as invalid. Offsetting an invalid address doesn't do anything.
//
// This distinction is useful because there are objects that we can't
// get the pointer to.
type address uintptr

const invalidAddr = address(0)

func (a address) valid() bool {
	return a != 0
}

func (a address) addOffset(off uintptr) address {
	if !a.valid() {
		return invalidAddr
	}
	return a + address(off)
}

func (a address) String() string {
	return fmt.Sprintf("%#x", uintptr(a))
}

type typCache map[reflect.Type]typInfo

type typInfo struct {
	isPointer bool
	needScan  bool
}

func (tc *typCache) isPointer(typ reflect.Type) bool {
	return tc.info(typ).isPointer
}

func (tc *typCache) needScan(typ reflect.Type) bool {
	return tc.info(typ).needScan
}

func (tc *typCache) info(typ reflect.Type) typInfo {
	if info, ok := (*tc)[typ]; ok {
		return info
	}
	info := tc.makeInfo(typ)
	(*tc)[typ] = info
	return info
}

func (tc *typCache) makeInfo(typ reflect.Type) typInfo {
	var ti typInfo
	ti.isPointer = isPointer(typ)
	ti.needScan = ti.isPointer
	k := typ.Kind()
	if k == reflect.Array {
		ti.needScan = tc.needScan(typ.Elem())
	} else if k >= reflect.Chan && k <= reflect.Struct {
		ti.needScan = true
	}
	return ti
}

func isPointer(typ reflect.Type) bool {
	k := typ.Kind()
	switch {
	case k <= reflect.Complex128:
		return false
	case k == reflect.Array:
		return false
	case k >= reflect.Chan && k <= reflect.String:
		return true
	case k == reflect.Struct || k == reflect.UnsafePointer:
		return false
	default:
		unhandledKind(k)
		return false
	}
}

func unhandledKind(k reflect.Kind) {
	panic("unhandled kind " + k.String())
}

func humanSize(bytes uintptr) string {
	switch {
	case bytes < 1024:
		return fmt.Sprintf("%d B", bytes)
	case bytes < 1024*1024:
		return fmt.Sprintf("%.3f KB", float64(bytes)/1024)
	default:
		return fmt.Sprintf("%.3f MB", float64(bytes)/1024/1024)
	}
}
<|endoftext|>


<commit_before>package platform

import "context"

// User is an user. 🎉
type User struct {
	ID   ID     `json:"id,omitempty"`
	Name string `json:"name"`
}

// UserService represents a service for managing user data.
type UserService interface {
	// Returns a single user by ID.
	FindUserByID(ctx context.Context, id ID) (*User, error)

	// Returns the first user that matches filter.
	FindUser(ctx context.Context, filter UserFilter) (*User, error)

	// Returns a list of users that match filter and the total count of matching users.
	// Additional options provide pagination & sorting.
	FindUsers(ctx context.Context, filter UserFilter, opt ...FindOptions) ([]*User, int, error)

	// Creates a new user and sets u.ID with the new identifier.
	CreateUser(ctx context.Context, u *User) error

	// Updates a single user with changeset.
	// Returns the new user state after update.
	UpdateUser(ctx context.Context, id ID, upd UserUpdate) (*User, error)

	// Removes a user by ID.
	DeleteUser(ctx context.Context, id ID) error
}

// BasicAuthService is the service for managing basic auth.
type BasicAuthService interface {
	SetPassword(ctx context.Context, name string, password string) error
	ComparePassword(ctx context.Context, name string, password string) error
	CompareAndSetPassword(ctx context.Context, name string, old string, new string) error
}

// UserUpdate represents updates to a user.
// Only fields which are set are updated.
type UserUpdate struct {
	Name *string `json:"name"`
}

// UserFilter represents a set of filter that restrict the returned results.
type UserFilter struct {
	ID   *ID
	Name *string
}
<commit_msg>fix(user): update comment about user service<commit_after>package platform

import "context"

// User is a user. 🎉
type User struct {
	ID   ID     `json:"id,omitempty"`
	Name string `json:"name"`
}

// UserService represents a service for managing user data.
type UserService interface {
	// Returns a single user by ID.
	FindUserByID(ctx context.Context, id ID) (*User, error)

	// Returns the first user that matches filter.
	FindUser(ctx context.Context, filter UserFilter) (*User, error)

	// Returns a list of users that match filter and the total count of matching users.
	// Additional options provide pagination & sorting.
	FindUsers(ctx context.Context, filter UserFilter, opt ...FindOptions) ([]*User, int, error)

	// Creates a new user and sets u.ID with the new identifier.
	CreateUser(ctx context.Context, u *User) error

	// Updates a single user with changeset.
	// Returns the new user state after update.
	UpdateUser(ctx context.Context, id ID, upd UserUpdate) (*User, error)

	// Removes a user by ID.
	DeleteUser(ctx context.Context, id ID) error
}

// BasicAuthService is the service for managing basic auth.
type BasicAuthService interface {
	SetPassword(ctx context.Context, name string, password string) error
	ComparePassword(ctx context.Context, name string, password string) error
	CompareAndSetPassword(ctx context.Context, name string, old string, new string) error
}

// UserUpdate represents updates to a user.
// Only fields which are set are updated.
type UserUpdate struct {
	Name *string `json:"name"`
}

// UserFilter represents a set of filter that restrict the returned results.
type UserFilter struct {
	ID   *ID
	Name *string
}
<|endoftext|>


<commit_before>// Copyright 2010 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

/*

Go Builder is a continuous build client for the Go project.
It integrates with the Go Dashboard AppEngine application.

Go Builder is intended to run continuously as a background process.

It periodically pulls updates from the Go Mercurial repository.

When a newer revision is found, Go Builder creates a clone of the repository,
runs all.bash, and reports build success or failure to the Go Dashboard.

For a successful build, Go Builder will also run benchmarks
(cd $GOROOT/src/pkg; make bench) and send the results to the Go Dashboard.

For a release revision (a change description that matches "release.YYYY-MM-DD"),
Go Builder will create a tar.gz archive of the GOROOT and deliver it to the
Go Google Code project's downloads section.

Usage:

  gobuilder goos-goarch...

  Several goos-goarch combinations can be provided, and the builder will
  build them in serial.

Optional flags:

  -dashboard="godashboard.appspot.com": Go Dashboard Host
    The location of the Go Dashboard application to which Go Builder will
    report its results.

  -bench: Run benchmarks

  -release: Build and deliver binary release archive

  -rev=N: Build revision N and exit

  -cmd="./all.bash": Build command (specify absolute or relative to go/src)

  -v: Verbose logging

  -external: External package builder mode (will not report Go build
     state to dashboard, issue releases, or run benchmarks)

The key file should be located at $HOME/.gobuilder or, for a builder-specific
key, $HOME/.gobuilder-$BUILDER (eg, $HOME/.gobuilder-linux-amd64).

The build key file is a text file of the format:

  godashboard-key
  googlecode-username
  googlecode-password

If the Google Code credentials are not provided the archival step
will be skipped.

*/
package documentation
<commit_msg>misc/dashboard/builder/doc.go: gofmt it<commit_after>// Copyright 2010 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

/*

Go Builder is a continuous build client for the Go project.
It integrates with the Go Dashboard AppEngine application.

Go Builder is intended to run continuously as a background process.

It periodically pulls updates from the Go Mercurial repository.

When a newer revision is found, Go Builder creates a clone of the repository,
runs all.bash, and reports build success or failure to the Go Dashboard.

For a successful build, Go Builder will also run benchmarks
(cd $GOROOT/src/pkg; make bench) and send the results to the Go Dashboard.

For a release revision (a change description that matches "release.YYYY-MM-DD"),
Go Builder will create a tar.gz archive of the GOROOT and deliver it to the
Go Google Code project's downloads section.

Usage:

  gobuilder goos-goarch...

  Several goos-goarch combinations can be provided, and the builder will
  build them in serial.

Optional flags:

  -dashboard="godashboard.appspot.com": Go Dashboard Host
    The location of the Go Dashboard application to which Go Builder will
    report its results.

  -bench: Run benchmarks

  -release: Build and deliver binary release archive

  -rev=N: Build revision N and exit

  -cmd="./all.bash": Build command (specify absolute or relative to go/src)

  -v: Verbose logging

  -external: External package builder mode (will not report Go build
     state to dashboard, issue releases, or run benchmarks)

The key file should be located at $HOME/.gobuilder or, for a builder-specific
key, $HOME/.gobuilder-$BUILDER (eg, $HOME/.gobuilder-linux-amd64).

The build key file is a text file of the format:

  godashboard-key
  googlecode-username
  googlecode-password

If the Google Code credentials are not provided the archival step
will be skipped.

*/
package documentation
<|endoftext|>


<commit_before>#!/bin/bash
#
# The "build" function below will later build a binary from a preprocessed
# source file. When "build" is called, these variables are set:
#
# - SOURCE:  the full path of the source file.
# - PREPROCESSED_SOURCE: the full path of the preprocessed source file,
#            i.e. without the leading #! line
# - BINARY:  the full path of the binary. The build function must generate
#            this file.
# - JITOS:   the host operating system
# - JITARCH: the host architecture.
#
function build() {
  # -- prepare go packages if needed.
  if [ -z "${GOPATH:-}" ]; then
    export GOPATH=$HOME/jit.golang
  fi

  local packages=$(
    < $SOURCE grep "// JIT_GO_PACKAGES="     | sed "sx// JIT_GO_PACKAGES=xx"
  )

  if [ "$packages" ]; then
  for package in "$packages" ; do
    go get $package
  done
  fi

  if [[ $JIT_DIST_BUILD = y ]]; then
    log "Building for distribution"
    local platforms=${JIT_GO_TARGET_PLATFORMS:-darwin.amd64 linux.amd64 linux.arm linux.386}
  else
    local platforms=$JITOS.$JITARCH
  fi

  local binary_base=$(echo $BINARY | sed 's-[.][^.]*[.][^.]*$--')

  local platform
  for platform in $platforms ; do
    local goos=$(cut -d . -f 1 <<<$platform)
    local goarch=$(cut -d . -f 2 <<<$platform)
    echo "===== cat $PREPROCESSED_SOURCE"

	if ! env GOARCH=$goarch GOOS=$goos go build -o $binary_base.$goos.$goarch $PREPROCESSED_SOURCE ; then
		exit 1
	fi

	log Built $binary_base.$goos.$goarch
  done
}

JIT_EXT=go
jit_inc=$(echo "$0" | sed 's-[.][^.]*$-.inc-')
. "$jit_inc"
<commit_msg>cleanup jit.go<commit_after>#!/bin/bash
#
# The "build" function below will later build a binary from a preprocessed
# source file. When "build" is called, these variables are set:
#
# - SOURCE:  the full path of the source file.
# - PREPROCESSED_SOURCE: the full path of the preprocessed source file,
#            i.e. without the leading #! line
# - BINARY:  the full path of the binary. The build function must generate
#            this file.
# - JITOS:   the host operating system
# - JITARCH: the host architecture.
#
function build() {
  # -- prepare go packages if needed.
  if [ -z "${GOPATH:-}" ]; then
    export GOPATH=$HOME/jit.golang
  fi

  local packages=$(
    < $SOURCE grep "// JIT_GO_PACKAGES="     | sed "sx// JIT_GO_PACKAGES=xx"
  )

  if [ "$packages" ]; then
  for package in "$packages" ; do
    go get $package
  done
  fi

  if [[ $JIT_DIST_BUILD = y ]]; then
    log "Building for distribution"
    local platforms=${JIT_GO_TARGET_PLATFORMS:-darwin.amd64 linux.amd64 linux.arm linux.386}
  else
    local platforms=$JITOS.$JITARCH
  fi

  local binary_base=$(echo $BINARY | sed 's-[.][^.]*[.][^.]*$--')

  local platform
  for platform in $platforms ; do
    local goos=$(cut -d . -f 1 <<<$platform)
    local goarch=$(cut -d . -f 2 <<<$platform)

	if ! env GOARCH=$goarch GOOS=$goos go build -o $binary_base.$goos.$goarch $PREPROCESSED_SOURCE ; then
		exit 1
	fi

	log Built $binary_base.$goos.$goarch
  done
}

JIT_EXT=go
jit_inc=$(echo "$0" | sed 's-[.][^.]*$-.inc-')
. "$jit_inc"
<|endoftext|>