<commit_before>package check

import (
	"bitbucket.org/kardianos/osext"
	"bytes"
	"encoding/hex"
	"encoding/json"
	"fmt"
	"github.com/inconshreveable/go-update"
	"io/ioutil"
	"net/http"
	"runtime"
)

type Initiative string

const (
	INITIATIVE_NEVER  = "never"
	INITIATIVE_AUTO   = "auto"
	INITIATIVE_MANUAL = "manual"
)

var NoUpdateAvailable error = fmt.Errorf("No update available")

type Params struct {
	// protocol version
	Version int `json:"version"`
	// identifier of the application to update
	AppId string `json:"app_id"`
	// version of the application updating itself
	AppVersion string `json:"app_version"`
	// operating system of target platform
	OS string `json:"-"`
	// hardware architecture of target platform
	Arch string `json:"-"`
	// application-level user identifier
	UserId string `json:"user_id"`
	// checksum of the binary to replace (used for returning diff patches)
	Checksum string `json:"checksum"`
	// tags for custom update channels
	Tags map[string]string `json:"tags"`
}

type Result struct {
	Initiative Initiative
	Url        string           // url where to download the updated application
	PatchUrl   string           // a URL to a patch to apply
	PatchType  update.PatchType // the patch format (only bsdiff supported at the moment)
	Version    string           // version of the new application
	Checksum   string           // expected checksum of the new application
	Signature  string           // signature for verifying update authenticity
}

// CheckForUpdate makes an HTTP post to a URL with the JSON serialized
// representation of Params. It returns the deserialized result object
// returned by the remote endpoint or an error. If you do not set
// OS/Arch, CheckForUpdate will populate them for you. Similarly, if
// Version is 0, it will be set to 1. Lastly, if Checksum is the empty
// string, it will be automatically be computed for the running program's
// executable file.
func (p *Params) CheckForUpdate(url string) (*Result, error) {
	if p.OS == "" {
		p.OS = runtime.GOOS
	}

	if p.Arch == "" {
		p.Arch = runtime.GOARCH
	}

	if p.Version == 0 {
		p.Version = 1
	}

	// ignore errors auto-populating the checksum
	// if it fails, you just won't be able to patch
	if p.Checksum == "" {
		p.Checksum = defaultChecksum()
	}<commit_msg>fix for assignment into nil map<commit_after>package check

import (
	"bitbucket.org/kardianos/osext"
	"bytes"
	"encoding/hex"
	"encoding/json"
	"fmt"
	"github.com/inconshreveable/go-update"
	"io/ioutil"
	"net/http"
	"runtime"
)

type Initiative string

const (
	INITIATIVE_NEVER  = "never"
	INITIATIVE_AUTO   = "auto"
	INITIATIVE_MANUAL = "manual"
)

var NoUpdateAvailable error = fmt.Errorf("No update available")

type Params struct {
	// protocol version
	Version int `json:"version"`
	// identifier of the application to update
	AppId string `json:"app_id"`
	// version of the application updating itself
	AppVersion string `json:"app_version"`
	// operating system of target platform
	OS string `json:"-"`
	// hardware architecture of target platform
	Arch string `json:"-"`
	// application-level user identifier
	UserId string `json:"user_id"`
	// checksum of the binary to replace (used for returning diff patches)
	Checksum string `json:"checksum"`
	// tags for custom update channels
	Tags map[string]string `json:"tags"`
}

type Result struct {
	Initiative Initiative
	Url        string           // url where to download the updated application
	PatchUrl   string           // a URL to a patch to apply
	PatchType  update.PatchType // the patch format (only bsdiff supported at the moment)
	Version    string           // version of the new application
	Checksum   string           // expected checksum of the new application
	Signature  string           // signature for verifying update authenticity
}

// CheckForUpdate makes an HTTP post to a URL with the JSON serialized
// representation of Params. It returns the deserialized result object
// returned by the remote endpoint or an error. If you do not set
// OS/Arch, CheckForUpdate will populate them for you. Similarly, if
// Version is 0, it will be set to 1. Lastly, if Checksum is the empty
// string, it will be automatically be computed for the running program's
// executable file.
func (p *Params) CheckForUpdate(url string) (*Result, error) {
    if p.Tags == nil {
        p.Tags = make(map[string]string)
    }

	if p.OS == "" {
		p.OS = runtime.GOOS
	}

	if p.Arch == "" {
		p.Arch = runtime.GOARCH
	}

	if p.Version == 0 {
		p.Version = 1
	}

	// ignore errors auto-populating the checksum
	// if it fails, you just won't be able to patch
	if p.Checksum == "" {
		p.Checksum = defaultChecksum()
	}
{'fraction_non_alphanumeric': 0.0939841575679726, 'fraction_numerical': 0.0017126953543138515, 'mean_word_length': 3.2783882783882783, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1300726', 'n_tokens_mistral': 1423, 'n_tokens_neox': 1392, 'n_words': 538}