Giter Club home page Giter Club logo

examples's Introduction

Cloud Native Go

Pre-Release Book Cover

The official companion repository for Cloud Native Go by Matthew Titmus (O'Reilly Media), available in pre-release now!

This repository is still a work in progress, and will be incomplete prior to the final release of the book.

(The code for Chapter 5 is especially quite a mess. Please don't judge me harshly yet. I know it's a mess. I promise that I'll clean it up before we go to print. But for now this is what I have.)

examples's People

Contributors

clockworksoul avatar dependabot[bot] avatar ivankuchin avatar justinrmiller avatar monegim avatar mshearer0 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

examples's Issues

Chapter 9: Testing TokenBucketv2

In testing TokenBucketv2 by sending curl requests from a single machine i found using r.remoteAddr as UID gave a different value everytime as a new port was assigned for each http request. The throttle therefore was not envoked.

To test i truncated r.remote Addr to just IP by removing port:

import strings

replacing r.remoteAddr in the call to throttled with strings.Split(r.RemoteAddr, ":")[0]

Chapter 8: Hexarch Filelogger - Negative WaitGroup Counter

Hexarch example fails with panic: sync: negative WaitGroup counter.

Removing extra wg.Done from Write methods of FileTransactionLogger solves the issue:

func (l *FileTransactionLogger) WritePut(key, value string) {
l.wg.Add(1)
l.events <- core.Event{EventType: core.EventPut, Key: key, Value: url.QueryEscape(value)}
// l.wg.Done()
}

func (l *FileTransactionLogger) WriteDelete(key string) {
l.wg.Add(1)
l.events <- core.Event{EventType: core.EventDelete, Key: key}
// l.wg.Done()
}

Ch. 8, Hexagonal Architecture, Restore() func not properly loading existing data.

Just wanted to inquire if anyone else Is having trouble with getting the FileLogger to load an existing log file.

If there is no existing file, I can run the program fine, it creates the log file, and writes to the file.

The problem lies in trying to run the program again, in which it hangs.

I've traced the problem to getting stuck the the Restore() function's for loop:

	for ok && err == nil {
		select {
		case err, ok = <-errors:
		case e, ok = <-events:
			switch e.EventType {
			case EventDelete:
				err = store.Delete(e.Key)
				count++
			case EventPut:
				err = store.Put(e.Key, e.Value)
				count++
			}
		}
	}

It's driving me crazy, wanted to see if anyone else had similar issues, or any idea on how to properly debug the issue.

Chapter 8: Hexarch Testlogger

func NewTestTransactionLogger() (core.TransactionLogger, error) { return TestTransactionLogger{}, nil}

Should return &TestTransactionLogger{}, nil

Chapter 5: Inconsistency with HTTP paths

Excellent book, there is just a simple miscommunication that I wanted to address.

In chapter 5, section Generation 1: The Monolith, page 117:

The URI for your key-value pair resources will have the form /v1/key/{key}, where {key} is the unique key string

In following pages, we also have:

  • It must only match PUT requests for /v1/key/{key}
  • It must only match GET requests for /v1/key/{key}

However, in the code sample provided on page 120, we are given:

func main() {
    r := mux.NewRouter()
    r.HandleFunc("/v1/{key}", keyValuePutHandler).Methods("PUT")
    r.HandleFunc("/v1/{key}", keyValueGetHandler).Methods("GET")
    log.Fatal(http.ListenAndServe(":8080", r))
}

This is inconsistent, since the code sample will match PUT/GET requests for v1/{key}, and requests to a /v1/key/{key} path will result in a 404 error being raised without a clear indication of what the user is doing wrong.

I understand that this is difficult to fix in the print of the book, but I am suggesting that a note of this should be made in the chapter 5 `README.md

Possible to lost tokens in refill function

In case when ctx that passed to Effector canceled by timeout before refill ticker fires - possible lost token. Here is example:

func TestRefill(t *testing.T) {
	const max uint = 1
	const refillDuration = time.Second

	callsCounter := 0
	effector := callsCountFunction(&callsCounter)

	// Any context with cancellation (WithTimeout, etc)
	ctx, cancel := context.WithCancel(context.Background())
	throttle := Throttle(effector, max, max, refillDuration)

	_, err := throttle(ctx)
	if err != nil {
		t.Fatal("unexpected error: ", err)
	}
	if callsCounter != 1 {
		t.Fatal("unexpected callsCounter value: ", callsCounter)
	}
	// Request cancelled by timeout before refillDuration. (If comment this line โ€“ test will be success)
	cancel()

	// Waiting token refill . x2 for ensure that token refiled
	time.Sleep(refillDuration * 2)

	ctx, cancel = context.WithCancel(context.Background())
	defer cancel()

	_, err = throttle(ctx)
	if err != nil {
		t.Fatal("unexpected error: ", err)
	}
	if callsCounter != 2 {
		t.Fatal("unexpected callsCounter value: ", callsCounter)
	}
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.