Skip to content

Instantly share code, notes, and snippets.

View rogpeppe's full-sized avatar

Roger Peppe rogpeppe

View GitHub Profile

Operator overloading in Go with contracts

Roger Peppe 2018-09-03

[Edit 2018-09-11 Reworked following feedback from @jba]

In his Go generics feedback document, Dominic Honnef writes "Contracts are nice, but where is the operator overloading?". In this document, I set down some thoughts about how operator overloading might be added to Go within the context of the new generics design, layered on top of the current design.

The central part would be a new package in the standard library. This package would hook a type-parameterized type up to chosen Go operators. The Go compiler would know how to rewrite operator syntax into method call syntax on associated interface methods. How that's done is implementation-defined, and the API itself is defined by a package, but contracts supply a way of reasoning about available operators without defining the mapping between operators and method names.

The compiler would be responsible for making sure exist

Revised generics design

Roger Peppe, 2018-09-01

One common response to the new generics design has been that contracts seem a bit too much like interfaces but not the same.

They are indeed very similar if you squint a little. Consider these two definitions:

type IReader interface {

Read([]byte)(int, error)

Go generics feedback

Roger Peppe 2018/08/30

Here are a few thoughts after looking through the generics document. In general, I really like it. In particular I like the fact that it admits general operations on generic types through an intuitive contract specification that looks just like regular Go.

Enable authentication via Candid

This means that users with an account that Candid recognizes can access the controller as long as they have appropriate permissions granted. Note that Candid usernames are given an @external suffix to distinguish them from controller-local usernames.

Note that identity-url can only be set at bootstrap time and cannot be changed later.

The allow-model-access=true setting allows users to access models

Keybase proof

I hereby claim:

  • I am rogpeppe on github.
  • I am rogpeppe (https://keybase.io/rogpeppe) on keybase.
  • I have a public key ASAmGpV4wzyMQ2BSFg9fM01cgRd1K3zWLNtx8Nzj_wWcawo

To claim this, I am signing this object:

SEQ (Stream start)

Syntax:

str: "+STR+"

This event represents the start of a YAML stream. A stream contains zero or more DOC nodes.

Refactoring Go code

One of the advantages of Go is that refactoring Go code is easier than in some other languages. This workshop will explore some of ways that Go code can be refactoried manually and automatically.

Why do we refactor code?

  • increasing code complexity
  • changing requirements

Refactoring Go code

One of the advantages of Go is that refactoring Go code is easier than in some other languages. This workshop will explore some of ways that Go code can be refactoried manually and automatically.

Why do we refactor code?

  • increasing code complexity
  • changing requirements

Introduction

This subordinate charm is used to configure nrpe (Nagios Remote Plugin Executor). It can be related to the nagios charm via the monitors relation and will pass a monitors yaml to nagios informing it of what checks to monitor.

Principal Relations

// isHTTPS reports whether the configuration
// is configured to use HTTPS.
func (config Config) isHTTPS() bool {
// Ignore any URL parsing error as that'll
// be handled by other code paths.
configURL, _ := url.Parse(config.URL)
return configURL != nil && configURL.Scheme == "https"
}