From f8160ca53d6dd76efa093face0657b9d5bf81a0c Mon Sep 17 00:00:00 2001
From: Teiva Harsanyi Enabling the In Go, the race detector isn’t a static analysis tool used during compilation; instead, it’s a tool to find data races that occur at runtime. To enable it, we have to enable the -race flag while compiling or running a test. For example: Once the race detector is enabled, the compiler instruments the code to detect data races. Instrumentation refers to a compiler adding extra instructions: here, tracking all memory accesses and recording when and how they occur. Enabling the race detector adds an overhead in terms of memory and execution time; hence, it's generally recommended to enable it only during local testing or continuous integration, not production. If a race is detected, Go raises a warning. For example: Runnig this code with the Let’s make sure we are comfortable reading these messages. Go always logs the following: In addition, if a specific file contains tests that lead to data races, we can (temporarily! ) exclude it from race detection using the This page is a summary of the mistakes in the 100 Go Mistakes and How to Avoid Them book. Meanwhile, it's also open to the community. If you believe that a common Go mistake should be added, please create an issue. Is your company hiring? Sponsor this repository and let a significant audience of Go developers (~1k unique visitors per week) know about your opportunities in this section. You're viewing a beta version enriched with significantly more content. However, this version is not yet complete, and I'm looking for volunteers to help me summarize the remaining mistakes (GitHub issue #43). Progress: Avoiding shadowed variables can help prevent mistakes like referencing the wrong variable or confusing readers. Variable shadowing occurs when a variable name is redeclared in an inner block, but this practice is prone to mistakes. Imposing a rule to forbid shadowed variables depends on personal taste. For example, sometimes it can be convenient to reuse an existing variable name like Source code Avoiding nested levels and keeping the happy path aligned on the left makes building a mental code model easier. In general, the more nested levels a function requires, the more complex it is to read and understand. Let\u2019s see some different applications of this rule to optimize our code for readability: Instead, we omit the Here, an empty Writing readable code is an important challenge for every developer. Striving to reduce the number of nested blocks, aligning the happy path on the left, and returning as early as possible are concrete means to improve our code\u2019s readability. Source code When initializing variables, remember that init functions have limited error handling and make state handling and testing more complex. In most cases, initializations should be handled as specific functions. An init function is a function used to initialize the state of an application. It takes no arguments and returns no result (a Init functions can lead to some issues: We should be cautious with init functions. They can be helpful in some situations, however, such as defining static configuration. Otherwise, and in most cases, we should handle initializations through ad hoc functions. Source code Forcing the use of getters and setters isn\u2019t idiomatic in Go. Being pragmatic and finding the right balance between efficiency and blindly following certain idioms should be the way to go. Data encapsulation refers to hiding the values or state of an object. Getters and setters are means to enable encapsulation by providing exported methods on top of unexported object fields. In Go, there is no automatic support for getters and setters as we see in some languages. It is also considered neither mandatory nor idiomatic to use getters and setters to access struct fields. We shouldn\u2019t overwhelm our code with getters and setters on structs if they don\u2019t bring any value. We should be pragmatic and strive to find the right balance between efficiency and following idioms that are sometimes considered indisputable in other programming paradigms. Remember that Go is a unique language designed for many characteristics, including simplicity. However, if we find a need for getters and setters or, as mentioned, foresee a future need while guaranteeing forward compatibility, there\u2019s nothing wrong with using them. Abstractions should be discovered, not created. To prevent unnecessary complexity, create an interface when you need it and not when you foresee needing it, or if you can at least prove the abstraction to be a valid one. Read the full section here. Source code Keeping interfaces on the client side avoids unnecessary abstractions. Interfaces are satisfied implicitly in Go, which tends to be a gamechanger compared to languages with an explicit implementation. In most cases, the approach to follow is similar to what we described in the previous section: abstractions should be discovered, not created. This means that it\u2019s not up to the producer to force a given abstraction for all the clients. Instead, it\u2019s up to the client to decide whether it needs some form of abstraction and then determine the best abstraction level for its needs. An interface should live on the consumer side in most cases. However, in particular contexts (for example, when we know\u2014not foresee\u2014that an abstraction will be helpful for consumers), we may want to have it on the producer side. If we do, we should strive to keep it as minimal as possible, increasing its reusability potential and making it more easily composable. Source code To prevent being restricted in terms of flexibility, a function shouldn\u2019t return interfaces but concrete implementations in most cases. Conversely, a function should accept interfaces whenever possible. In most cases, we shouldn\u2019t return interfaces but concrete implementations. Otherwise, it can make our design more complex due to package dependencies and can restrict flexibility because all the clients would have to rely on the same abstraction. Again, the conclusion is similar to the previous sections: if we know (not foresee) that an abstraction will be helpful for clients, we can consider returning an interface. Otherwise, we shouldn\u2019t force abstractions; they should be discovered by clients. If a client needs to abstract an implementation for whatever reason, it can still do that on the client\u2019s side. Only use The Source code Relying on generics and type parameters can prevent writing boilerplate code to factor out elements or behaviors. However, do not use type parameters prematurely, but only when you see a concrete need for them. Otherwise, they introduce unnecessary abstractions and complexity. Read the full section here. Source code Using type embedding can also help avoid boilerplate code; however, ensure that doing so doesn\u2019t lead to visibility issues where some fields should have remained hidden. When creating a struct, Go offers the option to embed types. But this can sometimes lead to unexpected behaviors if we don\u2019t understand all the implications of type embedding. Throughout this section, we look at how to embed types, what these bring, and the possible issues. In Go, a struct field is called embedded if it\u2019s declared without a name. For example, In the We use embedding to promote the fields and methods of an embedded type. Because Bar contains a Baz field, this field is promoted to What can we say about type embedding? First, let\u2019s note that it\u2019s rarely a necessity, and it means that whatever the use case, we can probably solve it as well without type embedding. Type embedding is mainly used for convenience: in most cases, to promote behaviors. If we decide to use type embedding, we need to keep two main constraints in mind: Using type embedding consciously by keeping these constraints in mind can help avoid boilerplate code with additional forwarding methods. However, let\u2019s make sure we don\u2019t do it solely for cosmetics and not promote elements that should remain hidden. Source code To handle options conveniently and in an API-friendly manner, use the functional options pattern. Although there are different implementations with minor variations, the main idea is as follows: The functional options pattern provides a handy and API-friendly way to handle options. Although the builder pattern can be a valid option, it has some minor downsides (having to pass a config struct that can be empty or a less handy way to handle error management) that tend to make the functional options pattern the idiomatic way to deal with these kind of problems in Go. Source code Regarding the overall organization, there are different schools of thought. For example, should we organize our application by context or by layer? It depends on our preferences. We may favor grouping code per context (such as the customer context, the contract context, etc.), or we may favor following hexagonal architecture principles and group per technical layer. If the decision we make fits our use case, it cannot be a wrong decision, as long as we remain consistent with it. Regarding packages, there are multiple best practices that we should follow. First, we should avoid premature packaging because it might cause us to overcomplicate a project. Sometimes, it\u2019s better to use a simple organization and have our project evolve when we understand what it contains rather than forcing ourselves to make the perfect structure up front. Granularity is another essential thing to consider. We should avoid having dozens of nano packages containing only one or two files. If we do, it\u2019s because we have probably missed some logical connections across these packages, making our project harder for readers to understand. Conversely, we should also avoid huge packages that dilute the meaning of a package name. Package naming should also be considered with care. As we all know (as developers), naming is hard. To help clients understand a Go project, we should name our packages after what they provide, not what they contain. Also, naming should be meaningful. Therefore, a package name should be short, concise, expressive, and, by convention, a single lowercase word. Regarding what to export, the rule is pretty straightforward. We should minimize what should be exported as much as possible to reduce the coupling between packages and keep unnecessary exported elements hidden. If we are unsure whether to export an element or not, we should default to not exporting it. Later, if we discover that we need to export it, we can adjust our code. Let\u2019s also keep in mind some exceptions, such as making fields exported so that a struct can be unmarshaled with encoding/json. Organizing a project isn\u2019t straightforward, but following these rules should help make it easier to maintain. However, remember that consistency is also vital to ease maintainability. Therefore, let\u2019s make sure that we keep things as consistent as possible within a codebase. In 2023, the Go team has published an official guideline for organizing / structuring a Go project: go.dev/doc/modules/layout Naming is a critical piece of application design. Creating packages such as Also, bear in mind that naming a package after what it provides and not what it contains can be an efficient way to increase its expressiveness. Source code To avoid naming collisions between variables and packages, leading to confusion or perhaps even bugs, use unique names for each one. If this isn\u2019t feasible, use an import alias to change the qualifier to differentiate the package name from the variable name, or think of a better name. Package collisions occur when a variable name collides with an existing package name, preventing the package from being reused. We should prevent variable name collisions to avoid ambiguity. If we face a collision, we should either find another meaningful name or use an import alias. To help clients and maintainers understand your code\u2019s purpose, document exported elements. Documentation is an important aspect of coding. It simplifies how clients can consume an API but can also help in maintaining a project. In Go, we should follow some rules to make our code idiomatic: First, every exported element must be documented. Whether it is a structure, an interface, a function, or something else, if it\u2019s exported, it must be documented. The convention is to add comments, starting with the name of the exported element. As a convention, each comment should be a complete sentence that ends with punctuation. Also bear in mind that when we document a function (or a method), we should highlight what the function intends to do, not how it does it; this belongs to the core of a function and comments, not documentation. Furthermore, the documentation should ideally provide enough information that the consumer does not have to look at our code to understand how to use an exported element. When it comes to documenting a variable or a constant, we might be interested in conveying two aspects: its purpose and its content. The former should live as code documentation to be useful for external clients. The latter, though, shouldn\u2019t necessarily be public. To help clients and maintainers understand a package\u2019s scope, we should also document each package. The convention is to start the comment with Documenting our code shouldn\u2019t be a constraint. We should take the opportunity to make sure it helps clients and maintainers to understand the purpose of our code. To improve code quality and consistency, use linters and formatters. A linter is an automatic tool to analyze code and catch errors. The scope of this section isn\u2019t to give an exhaustive list of the existing linters; otherwise, it will become deprecated pretty quickly. But we should understand and remember why linters are essential for most Go projects. However, if you\u2019re not a regular user of linters, here is a list that you may want to use daily: Besides linters, we should also use code formatters to fix code style. Here is a list of some code formatters for you to try: Meanwhile, we should also look at golangci-lint (https://github.com/golangci/golangci-lint). It\u2019s a linting tool that provides a facade on top of many useful linters and formatters. Also, it allows running the linters in parallel to improve analysis speed, which is quite handy. Linters and formatters are a powerful way to improve the quality and consistency of our codebase. Let\u2019s take the time to understand which one we should use and make sure we automate their execution (such as a CI or Git precommit hook). When reading existing code, bear in mind that integer literals starting with Octal numbers start with a 0 (e.g., We should also note the other integer literal representations: We can also use an underscore character (_) as a separator for readability. For example, we can write 1 billion this way: Source code Because integer overflows and underflows are handled silently in Go, you can implement your own functions to catch them. In Go, an integer overflow that can be detected at compile time generates a compilation error. For example, However, at run time, an integer overflow or underflow is silent; this does not lead to an application panic. It is essential to keep this behavior in mind, because it can lead to sneaky bugs (for example, an integer increment or addition of positive integers that leads to a negative result). Source code Making floating-point comparisons within a given delta can ensure that your code is portable. When performing addition or subtraction, group the operations with a similar order of magnitude to favor accuracy. Also, perform multiplication and division before addition and subtraction. In Go, there are two floating-point types (if we omit imaginary numbers): float32 and float64. The concept of a floating point was invented to solve the major problem with integers: their inability to represent fractional values. To avoid bad surprises, we need to know that floating-point arithmetic is an approximation of real arithmetic. For that, we\u2019ll look at a multiplication example: We may expect this code to print the result of 1.0001 * 1.0001 = 1.00020001, right? However, running it on most x86 processors prints 1.0002, instead. Because Go\u2019s Source code Understanding the difference between slice length and capacity should be part of a Go developer\u2019s core knowledge. The slice length is the number of available elements in the slice, whereas the slice capacity is the number of elements in the backing array. Read the full section here. Source code When creating a slice, initialize it with a given length or capacity if its length is already known. This reduces the number of allocations and improves performance. While initializing a slice using Our options are to allocate a slice with either a given capacity or a given length. Of these two solutions, we have seen that the second tends to be slightly faster. But using a given capacity and append can be easier to implement and read in some contexts. Source code To prevent common confusions such as when using the In Go, there is a distinction between nil and empty slices. A nil slice is equals to The last option, Source code To check if a slice doesn\u2019t contain any element, check its length. This check works regardless of whether the slice is To determine whether a slice has elements, we can either do it by checking if the slice is nil or if its length is equal to 0. Checking the length is the best option to follow as it will cover both if the slice is empty or if the slice is nil. Meanwhile, when designing interfaces, we should avoid distinguishing nil and empty slices, which leads to subtle programming errors. When returning slices, it should make neither a semantic nor a technical difference if we return a nil or empty slice. Both should mean the same thing for the callers. This principle is the same with maps. To check if a map is empty, check its length, not whether it\u2019s nil. Source code To copy one slice to another using the Copying elements from one slice to another is a reasonably frequent operation. When using copy, we must recall that the number of elements copied to the destination corresponds to the minimum between the two slices\u2019 lengths. Also bear in mind that other alternatives exist to copy a slice, so we shouldn\u2019t be surprised if we find them in a codebase. Source code Using copy or the full slice expression is a way to prevent When using slicing, we must remember that we can face a situation leading to unintended side effects. If the resulting slice has a length smaller than its capacity, append can mutate the original slice. If we want to restrict the range of possible side effects, we can use either a slice copy or the full slice expression, which prevents us from doing a copy. Source code Working with a slice of pointers or structs with pointer fields, you can avoid memory leaks by marking as nil the elements excluded by a slicing operation. Remember that slicing a large slice or array can lead to potential high memory consumption. The remaining space won\u2019t be reclaimed by the GC, and we can keep a large backing array despite using only a few elements. Using a slice copy is the solution to prevent such a case. Source code When we use the slicing operation with pointers or structs with pointer fields, we need to know that the GC won\u2019t reclaim these elements. In that case, the two options are to either perform a copy or explicitly mark the remaining elements or their fields to Source code When creating a map, initialize it with a given length if its length is already known. This reduces the number of allocations and improves performance. A map provides an unordered collection of key-value pairs in which all the keys are distinct. In Go, a map is based on the hash table data structure. Internally, a hash table is an array of buckets, and each bucket is a pointer to an array of key-value pairs. If we know up front the number of elements a map will contain, we should create it by providing an initial size. Doing this avoids potential map growth, which is quite heavy computation-wise because it requires reallocating enough space and rebalancing all the elements. Source code A map can always grow in memory, but it never shrinks. Hence, if it leads to some memory issues, you can try different options, such as forcing Go to recreate the map or using pointers. Read the full section here. Source code To compare types in Go, you can use the == and != operators if two types are comparable: Booleans, numerals, strings, pointers, channels, and structs are composed entirely of comparable types. Otherwise, you can either use It\u2019s essential to understand how to use We can also use the If operands are not comparable (e.g., slices and maps), we have to use other options such as reflection. Reflection is a form of metaprogramming, and it refers to the ability of an application to introspect and modify its structure and behavior. For example, in Go, we can use If performance is crucial at run time, implementing our custom method might be the best solution. One additional note: we must remember that the standard library has some existing comparison methods. For example, we can use the optimized Source code The value element in a A range loop allows iterating over different data structures: Compared to a classic for Yet, we should remember that the value element in a range loop is a copy. Therefore, if the value is a struct we need to mutate, we will only update the copy, not the element itself, unless the value or field we modify is a pointer. The favored options are to access the element via the index using a range loop or a classic for loop. Source code Understanding that the expression passed to the The range loop evaluates the provided expression only once, before the beginning of the loop, by doing a copy (regardless of the type). We should remember this behavior to avoid common mistakes that might, for example, lead us to access the wrong element. For example: This code updates the last index to 10. However, if we run this code, it does not print 10; it prints 2. Source code This mistake isn't relevant anymore from Go 1.22 (details). To ensure predictable outputs when using maps, remember that a map data structure: Source code Using A break statement is commonly used to terminate the execution of a loop. When loops are used in conjunction with switch or select, developers frequently make the mistake of breaking the wrong statement. For example: The break statement doesn\u2019t terminate the One essential rule to keep in mind is that a To break the loop instead of the Here, we associate the Source code Extracting loop logic inside a function leads to executing a The One common mistake with The One common option to fix this problem is to create a surrounding function after Another solution is to make the Source code Understanding that a rune corresponds to the concept of a Unicode code point and that it can be composed of multiple bytes should be part of the Go developer\u2019s core knowledge to work accurately with strings. As runes are everywhere in Go, it's important to understand the following: Source code Iterating on a string with the Iterating on a string is a common operation for developers. Perhaps we want to perform an operation for each rune in the string or implement a custom function to search for a specific substring. In both cases, we have to iterate on the different runes of a string. But it\u2019s easy to get confused about how iteration works. For example, consider the following example: Let's highlight three points that might be confusing: Let\u2019s start with the last observation. We already mentioned that len returns the number of bytes in a string, not the number of runes. Because we assigned a string literal to Meanwhile, in the previous example, we have to understand that we don't iterate over each rune; instead, we iterate over each starting index of a rune: Printing If we want to print all the different runes, we can either use the value element of the Or, we can convert the string into a slice of runes and iterate over it: Note that this solution introduces a run-time overhead compared to the previous one. Indeed, converting a string into a slice of runes requires allocating an additional slice and converting the bytes into runes: an O(n) time complexity with n the number of bytes in the string. Therefore, if we want to iterate over all the runes, we should use the first solution. However, if we want to access the ith rune of a string with the first option, we don\u2019t have access to the rune index; rather, we know the starting index of a rune in the byte sequence. Source code For example: The example prints 123: Conversely, On the other side, Source code Concatenating a list of strings should be done with Let\u2019s consider a During each iteration, the Fortunately, there is a solution to deal with this problem, using During each iteration, we constructed the resulting string by calling the Internally, Let\u2019s run a benchmark to compare the three versions (v1 using As we can see, the latest version is by far the most efficient: 99% faster than v1 and 78% faster than v2. Source code Remembering that the When choosing to work with a string or a When we\u2019re wondering whether we should work with strings or Source code Using copies instead of substrings can prevent memory leaks, as the string returned by a substring operation will be backed by the same byte array. In mistake #26, \u201cSlices and memory leaks,\u201d we saw how slicing a slice or array may lead to memory leak situations. This principle also applies to string and substring operations. We need to keep two things in mind while using the substring operation in Go. First, the interval provided is based on the number of bytes, not the number of runes. Second, a substring operation may lead to a memory leak as the resulting substring will share the same backing array as the initial string. The solutions to prevent this case from happening are to perform a string copy manually or to use Source code The decision whether to use a value or a pointer receiver should be made based on factors such as the type, whether it has to be mutated, whether it contains a field that can\u2019t be copied, and how large the object is. When in doubt, use a pointer receiver. Choosing between value and pointer receivers isn\u2019t always straightforward. Let\u2019s discuss some of the conditions to help us choose. A receiver must be a pointer A receiver should be a pointer A receiver must be a value A receiver should be a value Of course, it\u2019s impossible to be exhaustive, as there will always be edge cases, but this section\u2019s goal was to provide guidance to cover most cases. By default, we can choose to go with a value receiver unless there\u2019s a good reason not to do so. In doubt, we should use a pointer receiver. Source code Using named result parameters can be an efficient way to improve the readability of a function/method, especially if multiple result parameters have the same type. In some cases, this approach can also be convenient because named result parameters are initialized to their zero value. But be cautious about potential side effects. When we return parameters in a function or a method, we can attach names to these parameters and use them as regular variables. When a result parameter is named, it\u2019s initialized to its zero value when the function/method begins. With named result parameters, we can also call a naked return statement (without arguments). In that case, the current values of the result parameters are used as the returned values. Here\u2019s an example that uses a named result parameter In this example, we attach a name to the result parameter: In some cases, named result parameters can also increase readability: for example, if two parameters have the same type. In other cases, they can also be used for convenience. Therefore, we should use named result parameters sparingly when there\u2019s a clear benefit. Source code See #43. We mentioned why named result parameters can be useful in some situations. But as these result parameters are initialized to their zero value, using them can sometimes lead to subtle bugs if we\u2019re not careful enough. For example, can you spot what\u2019s wrong with this code? The error might not be obvious at first glance. Here, the error returned in the When using named result parameters, we must recall that each parameter is initialized to its zero value. As we have seen in this section, this can lead to subtle bugs that aren\u2019t always straightforward to spot while reading code. Therefore, let\u2019s remain cautious when using named result parameters, to avoid potential side effects. Source code When returning an interface, be cautious about not returning a nil pointer but an explicit nil value. Otherwise, unintended consequences may occur and the caller will receive a non-nil value. Source code Designing functions to receive Accepting a filename as a function input to read from a file should, in most cases, be considered a code smell (except in specific functions such as Source code Passing a pointer to a In a Indeed, we call Two leading options if we want to keep using The first solution is to pass a string pointer: Using There\u2019s another solution: calling a closure (an anonymous function value that references variables from outside its body) as a Here, we wrap the calls to both Let's also note this behavior applies with method receiver: the receiver is evaluated immediately. Source code Using In Go, panic is a built-in function that stops the ordinary flow: This code prints a and then stops before printing b: Panicking in Go should be used sparingly. There are two prominent cases, one to signal a programmer error (e.g., Source code Wrapping an error allows you to mark an error and/or provide additional context. However, error wrapping creates potential coupling as it makes the source error available for the caller. If you want to prevent that, don\u2019t use error wrapping. Since Go 1.13, the %w directive allows us to wrap errors conveniently. Error wrapping is about wrapping or packing an error inside a wrapper container that also makes the source error available. In general, the two main use cases for error wrapping are the following: When handling an error, we can decide to wrap it. Wrapping is about adding additional context to an error and/or marking an error as a specific type. If we need to mark an error, we should create a custom error type. However, if we just want to add extra context, we should use fmt.Errorf with the %w directive as it doesn\u2019t require creating a new error type. Yet, error wrapping creates potential coupling as it makes the source error available for the caller. If we want to prevent it, we shouldn\u2019t use error wrapping but error transformation, for example, using fmt.Errorf with the %v directive. Source code If you use Go 1.13 error wrapping with the Source code If you use Go 1.13 error wrapping with the A sentinel error is an error defined as a global variable: In general, the convention is to start with If we use error wrapping in our application with the Source code In most situations, an error should be handled only once. Logging an error is handling an error. Therefore, you have to choose between logging or returning an error. In many cases, error wrapping is the solution as it allows you to provide additional context to an error and return the source error. Handling an error multiple times is a mistake made frequently by developers, not specifically in Go. This can cause situations where the same error is logged multiple times make debugging harder. Let's remind us that handling an error should be done only once. Logging an error is handling an error. Hence, we should either log or return an error. By doing this, we simplify our code and gain better insights into the error situation. Using error wrapping is the most convenient approach as it allows us to propagate the source error and add context to an error. Source code Ignoring an error, whether during a function call or in a Source code In many cases, you shouldn\u2019t ignore an error returned by a Consider the following code: From a maintainability perspective, the code can lead to some issues. Let\u2019s consider a new reader looking at it. This reader notices that notify returns an error but that the error isn\u2019t handled by the parent function. How can they guess whether or not handling the error was intentional? How can they know whether the previous developer forgot to handle it or did it purposely? For these reasons, when we want to ignore an error, there's only one way to do it, using the blank identifier ( In terms of compilation and run time, this approach doesn\u2019t change anything compared to the first piece of code. But this new version makes explicit that we aren\u2019t interested in the error. Also, we can add a comment that indicates the rationale for why an error is ignored: Source code Understanding the fundamental differences between concurrency and parallelism is a cornerstone of the Go developer\u2019s knowledge. Concurrency is about structure, whereas parallelism is about execution. Concurrency and parallelism are not the same: In summary, concurrency provides a structure to solve a problem with parts that may be parallelized. Therefore, concurrency enables parallelism. To be a proficient developer, you must acknowledge that concurrency isn\u2019t always faster. Solutions involving parallelization of minimal workloads may not necessarily be faster than a sequential implementation. Benchmarking sequential versus concurrent solutions should be the way to validate assumptions. Read the full section here. Source code Being aware of goroutine interactions can also be helpful when deciding between channels and mutexes. In general, parallel goroutines require synchronization and hence mutexes. Conversely, concurrent goroutines generally require coordination and orchestration and hence channels. Given a concurrency problem, it may not always be clear whether we can implement a solution using channels or mutexes. Because Go promotes sharing memory by communication, one mistake could be to always force the use of channels, regardless of the use case. However, we should see the two options as complementary. When should we use channels or mutexes? We will use the example in the next figure as a backbone. Our example has three different goroutines with specific relationships: In general, parallel goroutines have to synchronize: for example, when they need to access or mutate a shared resource such as a slice. Synchronization is enforced with mutexes but not with any channel types (not with buffered channels). Hence, in general, synchronization between parallel goroutines should be achieved via mutexes. Conversely, in general, concurrent goroutines have to coordinate and orchestrate. For example, if G3 needs to aggregate results from both G1 and G2, G1 and G2 need to signal to G3 that a new intermediate result is available. This coordination falls under the scope of communication\u2014therefore, channels. Regarding concurrent goroutines, there\u2019s also the case where we want to transfer the ownership of a resource from one step (G1 and G2) to another (G3); for example, if G1 and G2 are enriching a shared resource and at some point, we consider this job as complete. Here, we should use channels to signal that a specific resource is ready and handle the ownership transfer. Mutexes and channels have different semantics. Whenever we want to share a state or access a shared resource, mutexes ensure exclusive access to this resource. Conversely, channels are a mechanic for signaling with or without data ( Being proficient in concurrency also means understanding that data races and race conditions are different concepts. Data races occur when multiple goroutines simultaneously access the same memory location and at least one of them is writing. Meanwhile, being data-race-free doesn\u2019t necessarily mean deterministic execution. When a behavior depends on the sequence or the timing of events that can\u2019t be controlled, this is a race condition. Race problems can be among the hardest and most insidious bugs a programmer can face. As Go developers, we must understand crucial aspects such as data races and race conditions, their possible impacts, and how to avoid them. A data race occurs when two or more goroutines simultaneously access the same memory location and at least one is writing. In this case, the result can be hazardous. Even worse, in some situations, the memory location may end up holding a value containing a meaningless combination of bits. We can prevent a data race from happening using different techniques. For example: Depending on the operation we want to perform, does a data-race-free application necessarily mean a deterministic result? Not necessarily. A race condition occurs when the behavior depends on the sequence or the timing of events that can\u2019t be controlled. Here, the timing of events is the goroutines\u2019 execution order. In summary, when we work in concurrent applications, it\u2019s essential to understand that a data race is different from a race condition. A data race occurs when multiple goroutines simultaneously access the same memory location and at least one of them is writing. A data race means unexpected behavior. However, a data-race-free application doesn\u2019t necessarily mean deterministic results. An application can be free of data races but still have behavior that depends on uncontrolled events (such as goroutine execution, how fast a message is published to a channel, or how long a call to a database lasts); this is a race condition. Understanding both concepts is crucial to becoming proficient in designing concurrent applications. Source code When creating a certain number of goroutines, consider the workload type. Creating CPU-bound goroutines means bounding this number close to the In programming, the execution time of a workload is limited by one of the following: The last is the rarest nowadays, given that memory has become very cheap in recent decades. Hence, this section focuses on the two first workload types: CPU- and I/O-bound. If the workload executed by the workers is I/O-bound, the value mainly depends on the external system. Conversely, if the workload is CPU-bound, the optimal number of goroutines is close to the number of available CPU cores (a best practice can be to use Source code Go contexts are also one of the cornerstones of concurrency in Go. A context allows you to carry a deadline, a cancellation signal, and/or a list of keys-values. https://pkg.go.dev/context A Context carries a deadline, a cancellation signal, and other values across API boundaries. A deadline refers to a specific point in time determined with one of the following: The semantics of a deadline convey that an ongoing activity should be stopped if this deadline is met. An activity is, for example, an I/O request or a goroutine waiting to receive a message from a channel. Another use case for Go contexts is to carry a cancellation signal. Let\u2019s imagine that we want to create an application that calls The last use case for Go contexts is to carry a key-value list. What\u2019s the point of having a context carrying a key-value list? Because Go contexts are generic and mainstream, there are infinite use cases. For example, if we use tracing, we may want different subfunctions to share the same correlation ID. Some developers may consider this ID too invasive to be part of the function signature. In this regard, we could also decide to include it as part of the provided context. The One thing to note is that the internal channel should be closed when a context is canceled or has met a deadline, instead of when it receives a specific value, because the closure of a channel is the only channel action that all the consumer goroutines will receive. This way, all the consumers will be notified once a context is canceled or a deadline is reached. In summary, to be a proficient Go developer, we have to understand what a context is and how to use it. In general, a function that users wait for should take a context, as doing so allows upstream callers to decide when calling this function should be aborted. Source code Understanding the conditions when a context can be canceled should matter when propagating it: for example, an HTTP handler canceling the context when the response has been sent. In many situations, it is recommended to propagate Go contexts. However, context propagation can sometimes lead to subtle bugs, preventing subfunctions from being correctly executed. Let\u2019s consider the following example. We expose an HTTP handler that performs some tasks and returns a response. But just before returning the response, we also want to send it to a Kafka topic. We don\u2019t want to penalize the HTTP consumer latency-wise, so we want the publish action to be handled asynchronously within a new goroutine. We assume that we have at our disposal a What\u2019s wrong with this piece of code? We have to know that the context attached to an HTTP request can cancel in different conditions: In the first two cases, we probably handle things correctly. For example, if we get a response from doSomeTask but the client has closed the connection, it\u2019s probably OK to call publish with a context already canceled so the message isn\u2019t published. But what about the last case? When the response has been written to the client, the context associated with the request will be canceled. Therefore, we are facing a race condition: In the latter case, calling publish will return an error because we returned the HTTP response quickly. From Go 1.21, there is a way to create a new context without cancel. In summary, propagating a context should be done cautiously. Source code Avoiding leaks means being mindful that whenever a goroutine is started, you should have a plan to stop it eventually. Goroutines are easy and cheap to start\u2014so easy and cheap that we may not necessarily have a plan for when to stop a new goroutine, which can lead to leaks. Not knowing when to stop a goroutine is a design issue and a common concurrency mistake in Go. Let\u2019s discuss a concrete example. We will design an application that needs to watch some external configuration (for example, using a database connection). Here\u2019s a first implementation: The problem with this code is that when the main goroutine exits (perhaps because of an OS signal or because it has a finite workload), the application is stopped. Hence, the resources created by watcher aren\u2019t closed gracefully. How can we prevent this from happening? One option could be to pass to newWatcher a context that will be canceled when main returns: We propagate the context created to the watch method. When the context is canceled, the watcher struct should close its resources. However, can we guarantee that watch will have time to do so? Absolutely not\u2014and that\u2019s a design flaw. The problem is that we used signaling to convey that a goroutine had to be stopped. We didn\u2019t block the parent goroutine until the resources had been closed. Let\u2019s make sure we do: Instead of signaling In summary, let\u2019s be mindful that a goroutine is a resource like any other that must eventually be closed to free memory or other resources. Starting a goroutine without knowing when to stop it is a design issue. Whenever a goroutine is started, we should have a clear plan about when it will stop. Last but not least, if a goroutine creates resources and its lifetime is bound to the lifetime of the application, it\u2019s probably safer to wait for this goroutine to complete before exiting the application. This way, we can ensure that the resources can be freed. Source code This mistake isn't relevant anymore from Go 1.22 (details). Understanding that One common mistake made by Go developers while working with channels is to make wrong assumptions about how select behaves with multiple channels. For example, let's consider the following case ( If we run this example multiple times, the result will be random: Instead of consuming the 10 messages, we only received a few of them. What\u2019s the reason? It lies in the specification of the select statement with multiple channels (https:// go.dev/ref/spec): Quote If one or more of the communications can proceed, a single one that can proceed is chosen via a uniform pseudo-random selection. Unlike a switch statement, where the first case with a match wins, the select statement selects randomly if multiple options are possible. This behavior might look odd at first, but there\u2019s a good reason for it: to prevent possible starvation. Suppose the first possible communication chosen is based on the source order. In that case, we may fall into a situation where, for example, we only receive from one channel because of a fast sender. To prevent this, the language designers decided to use a random selection. When using Source code Send notifications using a Channels are a mechanism for communicating across goroutines via signaling. A signal can be either with or without data. Let\u2019s look at a concrete example. We will create a channel that will notify us whenever a certain disconnection occurs. One idea is to handle it as a Now, let\u2019s say we interact with an API that provides us with such a channel. Because it\u2019s a channel of Booleans, we can receive either If that\u2019s the case, meaning we don\u2019t need a specific value to convey some information, we need a channel without data. The idiomatic way to handle it is a channel of empty structs: Using nil channels should be part of your concurrency toolset because it allows you to remove cases from What should this code do? The principle is the same if we send a message to a nil channel. This goroutine blocks forever: Then what\u2019s the purpose of Go allowing messages to be received from or sent to a nil channel? For example, we can use nil channels to implement an idiomatic way to merge two channels: This elegant solution relies on nil channels to somehow remove one case from the Let\u2019s keep this idea in mind: nil channels are useful in some conditions and should be part of the Go developer\u2019s toolset when dealing with concurrent code. Source code Carefully decide on the right channel type to use, given a problem. Only unbuffered channels provide strong synchronization guarantees. For buffered channels, you should have a good reason to specify a channel size other than one. An unbuffered channel is a channel without any capacity. It can be created by either omitting the size or providing a 0 size: With an unbuffered channel (sometimes called a synchronous channel), the sender will block until the receiver receives data from the channel. Conversely, a buffered channel has a capacity, and it must be created with a size greater than or equal to 1: With a buffered channel, a sender can send messages while the channel isn\u2019t full. Once the channel is full, it will block until a receiver goroutine receives a message: The first send isn\u2019t blocking, whereas the second one is, as the channel is full at this stage. What's the main difference between unbuffered and buffered channels: If we need a buffered channel, what size should we provide? The default value we should use for buffered channels is its minimum: 1. So, we may approach the problem from this standpoint: is there any good reason not to use a value of 1? Here\u2019s a list of possible cases where we should use another size: If we are outside of these cases, using a different channel size should be done cautiously. Let\u2019s bear in mind that deciding about an accurate queue size isn\u2019t an easy problem: Martin Thompson Queues are typically always close to full or close to empty due to the differences in pace between consumers and producers. They very rarely operate in a balanced middle ground where the rate of production and consumption is evenly matched. Being aware that string formatting may lead to calling existing functions means watching out for possible deadlocks and other data races. It\u2019s pretty easy to forget the potential side effects of string formatting while working in a concurrent application. github.com/etcd-io/etcd/pull/7816 shows an example of an issue where a map's key was formatted based on a mutable values from a context. Can you see what the problem is in this code with a The problem here may not be straightforward. If the provided age is negative, we return an error. Because the error is formatted, using the One possible solution is to restrict the scope of the mutex lock: Yet, such an approach isn't always possible. In these conditions, we have to be extremely careful with string formatting. Another approach is to access the In concurrent applications, we should remain cautious about the possible side effects of string formatting. Source code Calling Should adding an element to a slice using Do you believe this example has a data race? The answer is no. In this example, we create a slice with Now, let\u2019s run the same example with a slight change in how we initialize The answer is yes. We create a slice with How can we prevent the data race if we want both goroutines to work on a slice containing the initial elements of We should remember that using append on a shared slice in concurrent applications can lead to a data race. Hence, it should be avoided. Source code Remembering that slices and maps are pointers can prevent common data races. Let's implement a Next, we add an Meanwhile, we have to implement a method to calculate the average balance for all the customers. One idea is to handle a minimal critical section this way: What's the problem with this code? If we run a test using the Internally, a map is a One possible solution is to protect the whole Another option, if the iteration operation isn\u2019t lightweight, is to work on an actual copy of the data and protect only the copy: Once we have made a deep copy, we release the mutex. The iterations are done on the copy outside of the critical section. In summary, we have to be careful with the boundaries of a mutex lock. In this section, we have seen why assigning an existing map (or an existing slice) to a map isn\u2019t enough to protect against data races. The new variable, whether a map or a slice, is backed by the same data set. There are two leading solutions to prevent this: protect the whole function, or work on a copy of the actual data. In all cases, let\u2019s be cautious when designing critical sections and make sure the boundaries are accurately defined. Source code To accurately use Source code You can send repeated notifications to multiple goroutines with Source code You can synchronize a group of goroutines and handle errors and contexts with the Source code Source code Remain cautious with functions accepting a Many common functions in the standard library accept a A developer with experience in other languages might assume that the following code creates a new However, because 1,000 We should always use the Comments
-
+
diff --git a/site/28-maps-memory-leaks/index.html b/site/28-maps-memory-leaks/index.html
index 16077fe9..185503ad 100644
--- a/site/28-maps-memory-leaks/index.html
+++ b/site/28-maps-memory-leaks/index.html
@@ -1110,7 +1110,7 @@ Comments
-
+
diff --git a/site/404.html b/site/404.html
index b81ce9ec..c2345d0a 100644
--- a/site/404.html
+++ b/site/404.html
@@ -861,7 +861,7 @@ 404 - Not found
-
+
diff --git a/site/5-interface-pollution/index.html b/site/5-interface-pollution/index.html
index 2e8c5934..a83126e4 100644
--- a/site/5-interface-pollution/index.html
+++ b/site/5-interface-pollution/index.html
@@ -1351,7 +1351,7 @@ Comments
-
+
diff --git a/site/56-concurrency-faster/index.html b/site/56-concurrency-faster/index.html
index 380a9c94..26880541 100644
--- a/site/56-concurrency-faster/index.html
+++ b/site/56-concurrency-faster/index.html
@@ -1261,7 +1261,7 @@ Comments
-
+
diff --git a/site/89-benchmarks/index.html b/site/89-benchmarks/index.html
index b0e97aed..65c7f2f7 100644
--- a/site/89-benchmarks/index.html
+++ b/site/89-benchmarks/index.html
@@ -1403,7 +1403,7 @@ Comments
-
+
diff --git a/site/9-generics/index.html b/site/9-generics/index.html
index 23e6c43c..28162d29 100644
--- a/site/9-generics/index.html
+++ b/site/9-generics/index.html
@@ -1260,7 +1260,7 @@ Comments
-
+
diff --git a/site/92-false-sharing/index.html b/site/92-false-sharing/index.html
index 353b4c61..adce64a9 100644
--- a/site/92-false-sharing/index.html
+++ b/site/92-false-sharing/index.html
@@ -1096,7 +1096,7 @@ Comments
-
+
diff --git a/site/98-profiling-execution-tracing/index.html b/site/98-profiling-execution-tracing/index.html
index d64fb9d7..e8143163 100644
--- a/site/98-profiling-execution-tracing/index.html
+++ b/site/98-profiling-execution-tracing/index.html
@@ -1447,7 +1447,7 @@ Comments
-
+
diff --git a/site/book/index.html b/site/book/index.html
index b2e331e9..33019898 100644
--- a/site/book/index.html
+++ b/site/book/index.html
@@ -1128,7 +1128,7 @@ About the Author
-
+
diff --git a/site/chapter-1/index.html b/site/chapter-1/index.html
index 524016a7..88fb54cf 100644
--- a/site/chapter-1/index.html
+++ b/site/chapter-1/index.html
@@ -1299,7 +1299,7 @@ Summary
-
+
diff --git a/site/external/index.html b/site/external/index.html
index 6a803f43..5a6ef0d3 100644
--- a/site/external/index.html
+++ b/site/external/index.html
@@ -1420,7 +1420,7 @@ Um ÓTIMO livro para programadores
-
+
diff --git a/site/index.html b/site/index.html
index a817eb46..3783fbc3 100644
--- a/site/index.html
+++ b/site/index.html
@@ -4945,6 +4945,64 @@
Not enabling the race flag (#83)
-race
flag is highly recommended when writing concurrent applications. Doing so allows you to catch potential data races that can lead to software bugs.package main
+
+import (
+ "fmt"
+)
+
+func main() {
+ i := 0
+ go func() { i++ }()
+ fmt.Println(i)
+}
+
-race
logs the following warning:==================
+WARNING: DATA RACE
+Write at 0x00c000026078 by goroutine 7: # (1)
+ main.main.func1()
+ /tmp/app/main.go:9 +0x4e
+
+Previous read at 0x00c000026078 by main goroutine: # (2)
+ main.main()
+ /tmp/app/main.go:10 +0x88
+
+Goroutine 7 (running) created at: # (3)
+ main.main()
+ /tmp/app/main.go:9 +0x7a
+==================
+
+
+
+
+!race
build tag://go:build !race
+
+package main
+
+import (
+ "testing"
+)
+
+func TestFoo(t *testing.T) {
+ // ...
+}
+
Not using test execution modes (parallel and shuffle) (#84)
TL;DR
@@ -5226,7 +5284,7 @@ Comments
-
+
diff --git a/site/ja/index.html b/site/ja/index.html
index f9231db3..317e488e 100644
--- a/site/ja/index.html
+++ b/site/ja/index.html
@@ -4897,7 +4897,7 @@ Comments
-
+
diff --git a/site/search/search_index.json b/site/search/search_index.json
index f290624f..941f3e05 100644
--- a/site/search/search_index.json
+++ b/site/search/search_index.json
@@ -1 +1 @@
-{"config":{"lang":["en"],"separator":"[\\s\\-]+","pipeline":["stopWordFilter"]},"docs":[{"location":"","title":"Common Go Mistakes","text":"err
for errors. Yet, in general, we should remain cautious because we now know that we can face a scenario where the code compiles, but the variable that receives the value is not the one expected.
if
block returns, we should omit the else
block in all cases. For example, we shouldn\u2019t write:if foo() {\n // ...\n return true\n} else {\n // ...\n}\n
else
block like this:if foo() {\n // ...\n return true\n}\n// ...\n
if s != \"\" {\n // ...\n} else {\n return errors.New(\"empty string\")\n}\n
s
represents the non-happy path. Hence, we should flip the condition like so:if s == \"\" {\n return errors.New(\"empty string\")\n}\n// ...\n
func()
function). When a package is initialized, all the constant and variable declarations in the package are evaluated. Then, the init functions are executed.
any
says nothing (#8)","text":"TL;DR any
if you need to accept or return any possible type, such as json.Marshal
. Otherwise, any
doesn\u2019t provide meaningful information and can lead to compile-time issues by allowing a caller to call methods with any data type.any
type can be helpful if there is a genuine need for accepting or returning any possible type (for instance, when it comes to marshaling or formatting). In general, we should avoid overgeneralizing the code we write at all costs. Perhaps a little bit of duplicated code might occasionally be better if it improves other aspects such as code expressiveness.type Foo struct {\n Bar // Embedded field\n}\n\ntype Bar struct {\n Baz int\n}\n
Foo
struct, the Bar
type is declared without an associated name; hence, it\u2019s an embedded field.Foo
. Therefore, Baz becomes available from Foo.
Foo.Baz()
instead of Foo.Bar.Baz()
). If this is the only rationale, let\u2019s not embed the inner type and use a field instead.
type Option func(options *options) error
. For example, WithPort
accepts an int
argument that represents the port and returns an Option
type that represents how to update the options
struct.type options struct {\n port *int\n}\n\ntype Option func(options *options) error\n\nfunc WithPort(port int) Option {\n return func(options *options) error {\n if port < 0 {\n return errors.New(\"port should be positive\")\n }\n options.port = &port\n return nil\n }\n}\n\nfunc NewServer(addr string, opts ...Option) ( *http.Server, error) {\n var options options\n for _, opt := range opts {\n err := opt(&options)\n if err != nil {\n return nil, err\n }\n }\n\n // At this stage, the options struct is built and contains the config\n // Therefore, we can implement our logic related to port configuration\n var port int\n if options.port == nil {\n port = defaultHTTPPort\n } else {\n if *options.port == 0 {\n port = randomPort()\n } else {\n port = *options.port\n }\n }\n\n // ...\n}\n
common
, util
, and shared
doesn\u2019t bring much value for the reader. Refactor such packages into meaningful and specific package names.// Package
followed by the package name. The first line of a package comment should be concise. That\u2019s because it will appear in the package. Then, we can provide all the information we need in the following lines.
0
are octal numbers. Also, to improve readability, make octal integers explicit by prefixing them with 0o
.010
is equal to 8 in base 10). To improve readability and avoid potential mistakes for future code readers, we should make octal numbers explicit using the 0o
prefix (e.g., 0o10
).
0b
or 0B
prefix (for example, 0b100
is equal to 4 in base 10)0x
or 0X
prefix (for example, 0xF
is equal to 15 in base 10)i
suffix (for example, 3i
)1_000_000_000
. We can also use the underscore character with other representations (for example, 0b00_00_01
).var counter int32 = math.MaxInt32 + 1\n
constant 2147483648 overflows int32\n
var n float32 = 1.0001\nfmt.Println(n * n)\n
float32
and float64
types are approximations, we have to bear a few rules in mind:
make
, we can provide a length and an optional capacity. Forgetting to pass an appropriate value for both of these parameters when it makes sense is a widespread mistake. Indeed, it can lead to multiple copies and additional effort for the GC to clean the temporary backing arrays. Performance-wise, there\u2019s no good reason not to give the Go runtime a helping hand.encoding/json
or the reflect
package, you need to understand the difference between nil and empty slices. Both are zero-length, zero-capacity slices, but only a nil slice doesn\u2019t require allocation.nil
, whereas an empty slice has a length of zero. A nil slice is empty, but an empty slice isn\u2019t necessarily nil
. Meanwhile, a nil slice doesn\u2019t require any allocation. We have seen throughout this section how to initialize a slice depending on the context by using
var s []string
if we aren\u2019t sure about the final length and the slice can be empty[]string(nil)
as syntactic sugar to create a nil and empty slicemake([]string, length)
if the future length is known[]string{}
, should be avoided if we initialize the slice without elements. Finally, let\u2019s check whether the libraries we use make the distinctions between nil and empty slices to prevent unexpected behaviors.nil
or empty. The same goes for maps. To design unambiguous APIs, you shouldn\u2019t distinguish between nil and empty slices.copy
built-in function, remember that the number of copied elements corresponds to the minimum between the two slice\u2019s lengths.append
from creating conflicts if two different functions use slices backed by the same array. However, only a slice copy prevents memory leaks if you want to shrink a large slice.s[low:high:max]
(full slice expression): This statement creates a slice similar to the one created with s[low:high]
, except that the resulting slice\u2019s capacity is equal to max - low
.nil
.reflect.DeepEqual
and pay the price of reflection or use custom implementations and libraries.==
and !=
to make comparisons effectively. We can use these operators on operands that are comparable:
Note ?
, >=
, <
, and >
operators with numeric types to compare values and with strings to compare their lexical order.reflect.DeepEqual
. This function reports whether two elements are deeply equal by recursively traversing two values. The elements it accepts are basic types plus arrays, structs, slices, maps, pointers, interfaces, and functions. Yet, the main catch is the performance penalty.bytes.Compare
function to compare two slices of bytes. Before implementing a custom method, we need to make sure we don\u2019t reinvent the wheel.range
loops (#30)","text":"TL;DR range
loop is a copy. Therefore, to mutate a struct, for example, access it via its index or via a classic for
loop (unless the element or the field you want to modify is a pointer).
loop
, a range
loop is a convenient way to iterate over all the elements of one of these data structures, thanks to its concise syntax.range
loops (channels and arrays) (#31)","text":"TL;DR range
operator is evaluated only once before the beginning of the loop can help you avoid common mistakes such as inefficient assignment in channel or slice iteration.a := [3]int{0, 1, 2}\nfor i, v := range a {\n a[2] = 10\n if i == 2 {\n fmt.Println(v)\n }\n}\n
range
loops (#32)","text":"Warning
break
statement works (#34)","text":"TL;DR break
or continue
with a label enforces breaking a specific statement. This can be helpful with switch
or select
statements inside loops.for i := 0; i < 5; i++ {\n fmt.Printf(\"%d \", i)\n\n switch i {\n default:\n case 2:\n break\n }\n}\n
for
loop: it terminates the switch
statement, instead. Hence, instead of iterating from 0 to 2, this code iterates from 0 to 4: 0 1 2 3 4
.break
statement terminates the execution of the innermost for
, switch
, or select
statement. In the previous example, it terminates the switch
statement.switch
statement, the most idiomatic way is to use a label:loop:\n for i := 0; i < 5; i++ {\n fmt.Printf(\"%d \", i)\n\n switch i {\n default:\n case 2:\n break loop\n }\n }\n
loop
label with the for
loop. Then, because we provide the loop
label to the break
statement, it breaks the loop, not the switch. Therefore, this new version will print 0 1 2
, as we expected.defer
inside a loop (#35)","text":"TL;DR defer
statement at the end of each iteration.defer
statement delays a call\u2019s execution until the surrounding function returns. It\u2019s mainly used to reduce boilerplate code. For example, if a resource has to be closed eventually, we can use defer
to avoid repeating the closure calls before every single return
.defer
is to forget that it schedules a function call when the surrounding function returns. For example:func readFiles(ch <-chan string) error {\n for path := range ch {\n file, err := os.Open(path)\n if err != nil {\n return err\n }\n\n defer file.Close()\n\n // Do something with file\n }\n return nil\n}\n
defer
calls are executed not during each loop iteration but when the readFiles
function returns. If readFiles
doesn\u2019t return, the file descriptors will be kept open forever, causing leaks.defer
, called during each iteration:func readFiles(ch <-chan string) error {\n for path := range ch {\n if err := readFile(path); err != nil {\n return err\n }\n }\n return nil\n}\n\nfunc readFile(path string) error {\n file, err := os.Open(path)\n if err != nil {\n return err\n }\n\n defer file.Close()\n\n // Do something with file\n return nil\n}\n
readFile
function a closure but intrinsically, this remains the same solution: adding another surrounding function to execute the defer
calls during each iteration.
rune
corresponds to the concept of a Unicode code point, meaning an item represented by a single value.len()
on a string in Go returns the number of bytes, not the number of runes.range
operator iterates on the runes with the index corresponding to the starting index of the rune\u2019s byte sequence. To access a specific rune index (such as the third rune), convert the string into a []rune
.s := \"h\u00eallo\"\nfor i := range s {\n fmt.Printf(\"position %d: %c\\n\", i, s[i])\n}\nfmt.Printf(\"len=%d\\n\", len(s))\n
position 0: h\nposition 1: \u00c3\nposition 3: l\nposition 4: l\nposition 5: o\nlen=6\n
s
, s
is a UTF-8 string. Meanwhile, the special character \"\u00ea\" isn\u2019t encoded in a single byte; it requires 2 bytes. Therefore, calling len(s)
returns 6.s[i]
doesn\u2019t print the ith rune; it prints the UTF-8 representation of the byte at index i
. Hence, we printed \"h\u00c3llo\" instead of \"h\u00eallo\".range
operator:s := \"h\u00eallo\"\nfor i, r := range s {\n fmt.Printf(\"position %d: %c\\n\", i, r)\n}\n
s := \"h\u00eallo\"\nrunes := []rune(s)\nfor i, r := range runes {\n fmt.Printf(\"position %d: %c\\n\", i, r)\n}\n
s := \"h\u00eallo\"\nr := []rune(s)[4]\nfmt.Printf(\"%c\\n\", r) // o\n
strings.TrimRight
/strings.TrimLeft
removes all the trailing/leading runes contained in a given set, whereas strings.TrimSuffix
/strings.TrimPrefix
returns a string without a provided suffix/prefix.fmt.Println(strings.TrimRight(\"123oxo\", \"xo\"))\n
strings.TrimLeft
removes all the leading runes contained in a set.strings.TrimSuffix
/ strings.TrimPrefix
returns a string without the provided trailing suffix / prefix.strings.Builder
to prevent allocating a new string during each iteration.concat
function that concatenates all the string elements of a slice using the +=
operator:func concat(values []string) string {\n s := \"\"\n for _, value := range values {\n s += value\n }\n return s\n}\n
+=
operator concatenates s
with the value string. At first sight, this function may not look wrong. But with this implementation, we forget one of the core characteristics of a string: its immutability. Therefore, each iteration doesn\u2019t update s
; it reallocates a new string in memory, which significantly impacts the performance of this function.strings.Builder
:func concat(values []string) string {\n sb := strings.Builder{}\n for _, value := range values {\n _, _ = sb.WriteString(value)\n }\n return sb.String()\n}\n
WriteString
method that appends the content of value to its internal buffer, hence minimizing memory copying.WriteString
returns an error as the second output, but we purposely ignore it. Indeed, this method will never return a non-nil error. So what\u2019s the purpose of this method returning an error as part of its signature? strings.Builder
implements the io.StringWriter
interface, which contains a single method: WriteString(s string) (n int, err error)
. Hence, to comply with this interface, WriteString
must return an error.strings.Builder
holds a byte slice. Each call to WriteString
results in a call to append on this slice. There are two impacts. First, this struct shouldn\u2019t be used concurrently, as the calls to append
would lead to race conditions. The second impact is something that we saw in mistake #21, \"Inefficient slice initialization\": if the future length of a slice is already known, we should preallocate it. For that purpose, strings.Builder
exposes a method Grow(n int)
to guarantee space for another n
bytes:func concat(values []string) string {\n total := 0\n for i := 0; i < len(values); i++ {\n total += len(values[i])\n }\n\n sb := strings.Builder{}\n sb.Grow(total) (2)\n for _, value := range values {\n _, _ = sb.WriteString(value)\n }\n return sb.String()\n}\n
+=
; v2 using strings.Builder{}
without preallocation; and v3 using strings.Builder{}
with preallocation). The input slice contains 1,000 strings, and each string contains 1,000 bytes:BenchmarkConcatV1-4 16 72291485 ns/op\nBenchmarkConcatV2-4 1188 878962 ns/op\nBenchmarkConcatV3-4 5922 190340 ns/op\n
strings.Builder
is the recommended solution to concatenate a list of strings. Usually, this solution should be used within a loop. Indeed, if we just have to concatenate a few strings (such as a name and a surname), using strings.Builder
is not recommended as doing so will make the code a bit less readable than using the +=
operator or fmt.Sprintf
.bytes
package offers the same operations as the strings
package can help avoid extra byte/string conversions.[]byte
, most programmers tend to favor strings for convenience. But most I/O is actually done with []byte
. For example, io.Reader
, io.Writer
, and io.ReadAll
work with []byte
, not strings.[]byte
, let\u2019s recall that working with []byte
isn\u2019t necessarily less convenient. Indeed, all the exported functions of the strings package also have alternatives in the bytes
package: Split
, Count
, Contains
, Index
, and so on. Hence, whether we\u2019re doing I/O or not, we should first check whether we could implement a whole workflow using bytes instead of strings and avoid the price of additional conversions.strings.Clone
from Go 1.18.
type slice []int\n\nfunc (s *slice) add(element int) {\n *s = append(*s, element)\n}\n
time.Time
.int
, float64
, or string
.b
:func f(a int) (b int) {\n b = a\n return\n}\n
b
. When we call return without arguments, it returns the current value of b
.func (l loc) getCoordinates(ctx context.Context, address string) (\n lat, lng float32, err error) {\n isValid := l.validateAddress(address) (1)\n if !isValid {\n return 0, 0, errors.New(\"invalid address\")\n }\n\n if ctx.Err() != nil { (2)\n return 0, 0, err\n }\n\n // Get and return coordinates\n}\n
if ctx.Err() != nil
scope is err
. But we haven\u2019t assigned any value to the err
variable. It\u2019s still assigned to the zero value of an error
type: nil
. Hence, this code will always return a nil error.io.Reader
types instead of filenames improves the reusability of a function and makes testing easier.os.Open
). Indeed, it makes unit tests more complex because we may have to create multiple files. It also reduces the reusability of a function (although not all functions are meant to be reused). Using the io.Reader
interface abstracts the data source. Regardless of whether the input is a file, a string, an HTTP request, or a gRPC request, the implementation can be reused and easily tested.defer
arguments and receivers are evaluated (argument evaluation, pointer, and value receivers) (#47)","text":"TL;DR defer
function and wrapping a call inside a closure are two possible solutions to overcome the immediate evaluation of arguments and receivers.defer
function the arguments are evaluated right away, not once the surrounding function returns. For example, in this code, we always call notify
and incrementCounter
with the same status: an empty string.const (\n StatusSuccess = \"success\"\n StatusErrorFoo = \"error_foo\"\n StatusErrorBar = \"error_bar\"\n)\n\nfunc f() error {\n var status string\n defer notify(status)\n defer incrementCounter(status)\n\n if err := foo(); err != nil {\n status = StatusErrorFoo\n return err\n }\n\n if err := bar(); err != nil {\n status = StatusErrorBar\n return err\n }\n\n status = StatusSuccess <5>\n return nil\n}\n
notify(status)
and incrementCounter(status)
as defer
functions. Therefore, Go will delay these calls to be executed once f
returns with the current value of status at the stage we used defer, hence passing an empty string.defer
.func f() error {\n var status string\n defer notify(&status) \n defer incrementCounter(&status)\n\n // The rest of the function unchanged\n}\n
defer
evaluates the arguments right away: here, the address of status. Yes, status itself is modified throughout the function, but its address remains constant, regardless of the assignments. Hence, if notify
or incrementCounter
uses the value referenced by the string pointer, it will work as expected. But this solution requires changing the signature of the two functions, which may not always be possible.defer
statement:func f() error {\n var status string\n defer func() {\n notify(status)\n incrementCounter(status)\n }()\n\n // The rest of the function unchanged\n}\n
notify
and incrementCounter
within a closure. This closure references the status variable from outside its body. Therefore, status
is evaluated once the closure is executed, not when we call defer
. This solution also works and doesn\u2019t require notify
and incrementCounter
to change their signature.panic
is an option to deal with errors in Go. However, it should only be used sparingly in unrecoverable conditions: for example, to signal a programmer error or when you fail to load a mandatory dependency.func main() {\n fmt.Println(\"a\")\n panic(\"foo\")\n fmt.Println(\"b\")\n}\n
a\npanic: foo\n\ngoroutine 1 [running]:\nmain.main()\n main.go:7 +0xb3\n
sql.Register
that panics if the driver is nil
or has already been register) and another where our application fails to create a mandatory dependency. Hence, exceptional conditions that lead us to stop the application. In most other cases, error management should be done with a function that returns a proper error type as the last return argument.
%w
directive and fmt.Errorf
, comparing an error against a type has to be done using errors.As
. Otherwise, if the returned error you want to check is wrapped, it will fail the checks.%w
directive and fmt.Errorf
, comparing an error against or a value has to be done using errors.As
. Otherwise, if the returned error you want to check is wrapped, it will fail the checks.import \"errors\"\n\nvar ErrFoo = errors.New(\"foo\")\n
Err
followed by the error type: here, ErrFoo
. A sentinel error conveys an expected error, an error that clients will expect to check. As general guidelines:
var ErrFoo = errors.New(\"foo\")
.type BarError struct { ... }
, with BarError
implementing the error
interface.%w
directive and fmt.Errorf
, checking an error against a specific value should be done using errors.Is
instead of ==
. Thus, even if the sentinel error is wrapped, errors.Is
can recursively unwrap it and compare each error in the chain against the provided value.defer
function, should be done explicitly using the blank identifier. Otherwise, future readers may be confused about whether it was intentional or a miss.defer
errors (#54)","text":"TL;DR defer
function. Either handle it directly or propagate it to the caller, depending on the context. If you want to ignore it, use the blank identifier.func f() {\n // ...\n notify() // Error handling is omitted\n}\n\nfunc notify() error {\n // ...\n}\n
_
):_ = notify\n
// At-most once delivery.\n// Hence, it's accepted to miss some of them in case of errors.\n_ = notify()\n
chan struct{}
or not). Coordination or ownership transfer should be achieved via channels. It\u2019s important to know whether goroutines are parallel or concurrent because, in general, we need mutexes for parallel goroutines and channels for concurrent ones.
"},{"location":"#race-condition","title":"Race Condition","text":"sync/atomic
packageGOMAXPROCS
variable (based by default on the number of CPU cores on the host). Creating I/O-bound goroutines depends on other factors, such as the external system.
Note runtime.GOMAXPROCS
). Knowing the workload type (I/O or CPU) is crucial when designing concurrent applications.
time.Duration
from now (for example, in 250 ms)time.Time
(for example, 2023-02-07 00:00:00 UTC)CreateFileWatcher(ctx context.Context, filename string)
within another goroutine. This function creates a specific file watcher that keeps reading from a file and catches updates. When the provided context expires or is canceled, this function handles it to close the file descriptor.context.Context
type exports a Done
method that returns a receive-only notification channel: <-chan struct{}
. This channel is closed when the work associated with the context should be canceled. For example,
context.WithCancel
is closed when the cancel function is called.context.WithDeadline
is closed when the deadline has expired.publish
function that accepts a context so the action of publishing a message can be interrupted if the context is canceled, for example. Here is a possible implementation:func handler(w http.ResponseWriter, r *http.Request) {\n response, err := doSomeTask(r.Context(), r)\n if err != nil {\n http.Error(w, err.Error(), http.StatusInternalServerError)\n return\n }\n go func() {\n err := publish(r.Context(), response)\n // Do something with err\n }()\n writeResponse(response)\n}\n
context.WithoutCancel
returns a copy of parent that is not canceled when parent is canceled.func main() {\n newWatcher()\n // Run the application\n}\n\ntype watcher struct { /* Some resources */ }\n\nfunc newWatcher() {\n w := watcher{}\n go w.watch() // Creates a goroutine that watches some external configuration\n}\n
func main() {\n ctx, cancel := context.WithCancel(context.Background())\n defer cancel()\n newWatcher(ctx)\n // Run the application\n}\n\nfunc newWatcher(ctx context.Context) {\n w := watcher{}\n go w.watch(ctx)\n}\n
func main() {\n w := newWatcher()\n defer w.close()\n // Run the application\n}\n\nfunc newWatcher() watcher {\n w := watcher{}\n go w.watch()\n return w\n}\n\nfunc (w watcher) close() {\n // Close the resources\n}\n
watcher
that it\u2019s time to close its resources, we now call this close
method, using defer
to guarantee that the resources are closed before the application exits.select
with multiple channels chooses the case randomly if multiple options are possible prevents making wrong assumptions that can lead to subtle concurrency bugs.disconnectCh
is a unbuffered channel):go func() {\n for i := 0; i < 10; i++ {\n messageCh <- i\n }\n disconnectCh <- struct{}{}\n}()\n\nfor {\n select {\n case v := <-messageCh:\n fmt.Println(v)\n case <-disconnectCh:\n fmt.Println(\"disconnection, return\")\n return\n }\n}\n
0\n1\n2\ndisconnection, return\n\n0\ndisconnection, return\n
select
with multiple channels, we must remember that if multiple options are possible, the first case in the source order does not automatically win. Instead, Go selects randomly, so there\u2019s no guarantee about which option will be chosen. To overcome this behavior, in the case of a single producer goroutine, we can use either unbuffered channels or a single channel.chan struct{}
type.chan bool
:disconnectCh := make(chan bool)\n
true
or false
messages. It\u2019s probably clear what true
conveys. But what does false
mean? Does it mean we haven\u2019t been disconnected? And in this case, how frequently will we receive such a signal? Does it mean we have reconnected? Should we even expect to receive false
? Perhaps we should only expect to receive true
messages.chan struct{}
.select
statements, for example.var ch chan int\n<-ch\n
ch
is a chan int
type. The zero value of a channel being nil, ch
is nil
. The goroutine won\u2019t panic; however, it will block forever.var ch chan int\nch <- 0\n
func merge(ch1, ch2 <-chan int) <-chan int {\n ch := make(chan int, 1)\n\n go func() {\n for ch1 != nil || ch2 != nil { // Continue if at least one channel isn\u2019t nil\n select {\n case v, open := <-ch1:\n if !open {\n ch1 = nil // Assign ch1 to a nil channel once closed\n break\n }\n ch <- v\n case v, open := <-ch2:\n if !open {\n ch2 = nil // Assigns ch2 to a nil channel once closed\n break\n }\n ch <- v\n }\n }\n close(ch)\n }()\n\n return ch\n}\n
select
statement.ch1 := make(chan int)\nch2 := make(chan int, 0)\n
ch3 := make(chan int, 1)\n
ch3 := make(chan int, 1)\nch3 <-1 // Non-blocking\nch3 <-2 // Blocking\n
Customer
struct exposing an UpdateAge
method and implementing the fmt.Stringer
interface?type Customer struct {\n mutex sync.RWMutex // Uses a sync.RWMutex to protect concurrent accesses\n id string\n age int\n}\n\nfunc (c *Customer) UpdateAge(age int) error {\n c.mutex.Lock() // Locks and defers unlock as we update Customer\n defer c.mutex.Unlock()\n\n if age < 0 { // Returns an error if age is negative\n return fmt.Errorf(\"age should be positive for customer %v\", c)\n }\n\n c.age = age\n return nil\n}\n\nfunc (c *Customer) String() string {\n c.mutex.RLock() // Locks and defers unlock as we read Customer\n defer c.mutex.RUnlock()\n return fmt.Sprintf(\"id %s, age %d\", c.id, c.age)\n}\n
%s
directive on the receiver, it will call the String
method to format Customer
. But because UpdateAge
already acquires the mutex lock, the String
method won\u2019t be able to acquire it. Hence, this leads to a deadlock situation. If all goroutines are also asleep, it leads to a panic.func (c *Customer) UpdateAge(age int) error {\n if age < 0 {\n return fmt.Errorf(\"age should be positive for customer %v\", c)\n }\n\n c.mutex.Lock() <1>\n defer c.mutex.Unlock()\n\n c.age = age\n return nil\n}\n
id
field directly:func (c *Customer) UpdateAge(age int) error {\n c.mutex.Lock()\n defer c.mutex.Unlock()\n\n if age < 0 {\n return fmt.Errorf(\"age should be positive for customer id %s\", c.id)\n }\n\n c.age = age\n return nil\n}\n
append
isn\u2019t always data-race-free; hence, it shouldn\u2019t be used concurrently on a shared slice.append
is data-race-free? Spoiler: it depends.s := make([]int, 1)\n\ngo func() { // In a new goroutine, appends a new element on s\n s1 := append(s, 1)\n fmt.Println(s1)\n}()\n\ngo func() { // Same\n s2 := append(s, 1)\n fmt.Println(s2)\n}()\n
make([]int, 1)
. The code creates a one-length, one-capacity slice. Thus, because the slice is full, using append in each goroutine returns a slice backed by a new array. It doesn\u2019t mutate the existing array; hence, it doesn\u2019t lead to a data race.s
. Instead of creating a slice with a length of 1, we create it with a length of 0 but a capacity of 1. How about this new example? Does it contain a data race?s := make([]int, 0, 1)\n\ngo func() { \n s1 := append(s, 1)\n fmt.Println(s1)\n}()\n\ngo func() {\n s2 := append(s, 1)\n fmt.Println(s2)\n}()\n
make([]int, 0, 1)
. Therefore, the array isn\u2019t full. Both goroutines attempt to update the same index of the backing array (index 1), which is a data race.s
plus an extra element? One solution is to create a copy of s
.Cache
struct used to handle caching for customer balances. This struct will contain a map of balances per customer ID and a mutex to protect concurrent accesses:type Cache struct {\n mu sync.RWMutex\n balances map[string]float64\n}\n
AddBalance
method that mutates the balances
map. The mutation is done in a critical section (within a mutex lock and a mutex unlock):func (c *Cache) AddBalance(id string, balance float64) {\n c.mu.Lock()\n c.balances[id] = balance\n c.mu.Unlock()\n}\n
func (c *Cache) AverageBalance() float64 {\n c.mu.RLock()\n balances := c.balances // Creates a copy of the balances map\n c.mu.RUnlock()\n\n sum := 0.\n for _, balance := range balances { // Iterates over the copy, outside of the critical section\n sum += balance\n }\n return sum / float64(len(balances))\n}\n
-race
flag with two concurrent goroutines, one calling AddBalance
(hence mutating balances) and another calling AverageBalance
, a data race occurs. What\u2019s the problem here?runtime.hmap
struct containing mostly metadata (for example, a counter) and a pointer referencing data buckets. So, balances := c.balances
doesn\u2019t copy the actual data. Therefore, the two goroutines perform operations on the same data set, and one mutates it. Hence, it's a data race.AverageBalance
function:func (c *Cache) AverageBalance() float64 {\n c.mu.RLock()\n defer c.mu.RUnlock() // Unlocks when the function returns\n\n sum := 0.\n for _, balance := range c.balances {\n sum += balance\n }\n return sum / float64(len(c.balances))\n}\n
func (c *Cache) AverageBalance() float64 {\n c.mu.RLock()\n m := make(map[string]float64, len(c.balances)) // Copies the map\n for k, v := range c.balances {\n m[k] = v\n }\n c.mu.RUnlock()\n\n sum := 0.\n for _, balance := range m {\n sum += balance\n }\n return sum / float64(len(m))\n}\n
sync.WaitGroup
(#71)","text":"TL;DR sync.WaitGroup
, call the Add
method before spinning up goroutines.sync.Cond
(#72)","text":"TL;DR sync.Cond
.errgroup
(#73)","text":"TL;DR errgroup
package.sync
type (#74)","text":"TL;DR sync
types shouldn\u2019t be copied.time.Duration
. Even though passing an integer is allowed, strive to use the time API to prevent any possible confusion.time.Duration
, which is an alias for the int64
type. However, one time.Duration
unit represents one nanosecond, instead of one millisecond, as commonly seen in other programming languages. As a result, passing numeric types instead of using the time.Duration
API can lead to unexpected behavior.time.Ticker
that delivers ticks every second, given the value 1000
:ticker := time.NewTicker(1000)\nfor {\n select {\n case <-ticker.C:\n // Do something\n }\n}\n
time.Duration
units = 1,000 nanoseconds, ticks are delivered every 1,000 nanoseconds = 1 microsecond, not every second as assumed.time.Duration
API to avoid confusion and unexpected behavior: ticker = time.NewTicker(time.Microsecond)\n// Or\nticker = time.NewTicker(1000 * time.Nanosecond)\n
Source code
"},{"location":"#timeafter-and-memory-leaks-76","title":"time.After
and memory leaks (#76)","text":"TL;DR Avoiding calls to time.After
in repeated functions (such as loops or HTTP handlers) can avoid peak memory consumption. The resources created by time.After
are released only when the timer expires.
Developers often use time.After
in loops or HTTP handlers repeatedly to implement the timing function. But it can lead to unintended peak memory consumption due to the delayed release of resources, just like the following code:
func consumer(ch <-chan Event) {\n for {\n select {\n case event := <-ch:\n handle(event)\n case <-time.After(time.Hour):\n log.Println(\"warning: no messages received\")\n }\n }\n}\n
The source code of the function time.After is as follows:
func After(d Duration) <-chan Time {\n return NewTimer(d).C\n}\n
As we see, it returns receive-only channel.
When time.After
is used in a loop or repeated context, a new channel is created in each iteration. If these channels are not properly closed or if their associated timers are not stopped, they can accumulate and consume memory. The resources associated with each timer and channel are only released when the timer expires or the channel is closed.
To avoid this happening, We can use context's timeout setting instead of time.After
, like below:
func consumer(ch <-chan Event) {\n for {\n ctx, cancel := context.WithTimeout(context.Background(), time.Hour)\n select {\n case event := <-ch:\n cancel()\n handle(event)\n case <-ctx.Done():\n log.Println(\"warning: no messages received\")\n }\n }\n}\n
We can also use time.NewTimer
like so:
func consumer(ch <-chan Event) {\n timerDuration := 1 * time.Hour\n timer := time.NewTimer(timerDuration)\n\n for {\n timer.Reset(timerDuration)\n select {\n case event := <-ch:\n handle(event)\n case <-timer.C:\n log.Println(\"warning: no messages received\")\n }\n }\n}\n
Source code
"},{"location":"#json-handling-common-mistakes-77","title":"JSON handling common mistakes (#77)","text":"Be careful about using embedded fields in Go structs. Doing so may lead to sneaky bugs like an embedded time.Time field implementing the json.Marshaler
interface, hence overriding the default marshaling behavior.
Source code
When comparing two time.Time
structs, recall that time.Time
contains both a wall clock and a monotonic clock, and the comparison using the == operator is done on both clocks.
Source code
any
To avoid wrong assumptions when you provide a map while unmarshaling JSON data, remember that numerics are converted to float64
by default.
Source code
"},{"location":"#common-sql-mistakes-78","title":"Common SQL mistakes (#78)","text":"sql.Open
doesn't necessarily establish connections to a databaseCall the Ping
or PingContext
method if you need to test your configuration and make sure a database is reachable.
Source code
Configure the database connection parameters for production-grade applications.
Using SQL prepared statements makes queries more efficient and more secure.
Source code
Deal with nullable columns in tables using pointers or sql.NullXXX
types.
Source code
Call the Err
method of sql.Rows
after row iterations to ensure that you haven\u2019t missed an error while preparing the next row.
Source code
"},{"location":"#not-closing-transient-resources-http-body-sqlrows-and-osfile-79","title":"Not closing transient resources (HTTP body,sql.Rows
, and os.File
) (#79)","text":"TL;DR Eventually close all structs implementing io.Closer
to avoid possible leaks.
Source code
"},{"location":"#forgetting-the-return-statement-after-replying-to-an-http-request-80","title":"Forgetting the return statement after replying to an HTTP request (#80)","text":"TL;DRTo avoid unexpected behaviors in HTTP handler implementations, make sure you don\u2019t miss the return
statement if you want a handler to stop after http.Error
.
Consider the following HTTP handler that handles an error from foo
using http.Error
:
func handler(w http.ResponseWriter, req *http.Request) {\n err := foo(req)\n if err != nil {\n http.Error(w, \"foo\", http.StatusInternalServerError)\n }\n\n _, _ = w.Write([]byte(\"all good\"))\n w.WriteHeader(http.StatusCreated)\n}\n
If we run this code and err != nil
, the HTTP response would be:
foo\nall good\n
The response contains both the error and success messages, and also the first HTTP status code, 500. There would also be a warning log indicating that we attempted to write the status code multiple times:
2023/10/10 16:45:33 http: superfluous response.WriteHeader call from main.handler (main.go:20)\n
The mistake in this code is that http.Error
does not stop the handler's execution, which means the success message and status code get written in addition to the error. Beyond an incorrect response, failing to return after writing an error can lead to the unwanted execution of code and unexpected side-effects. The following code adds the return
statement following the http.Error
and exhibits the desired behavior when ran:
func handler(w http.ResponseWriter, req *http.Request) {\n err := foo(req)\n if err != nil {\n http.Error(w, \"foo\", http.StatusInternalServerError)\n return // Adds the return statement\n }\n\n _, _ = w.Write([]byte(\"all good\"))\n w.WriteHeader(http.StatusCreated)\n}\n
Source code
"},{"location":"#using-the-default-http-client-and-server-81","title":"Using the default HTTP client and server (#81)","text":"TL;DRFor production-grade applications, don\u2019t use the default HTTP client and server implementations. These implementations are missing timeouts and behaviors that should be mandatory in production.
Source code
"},{"location":"#testing","title":"Testing","text":""},{"location":"#not-categorizing-tests-build-tags-environment-variables-and-short-mode-82","title":"Not categorizing tests (build tags, environment variables, and short mode) (#82)","text":"TL;DRCategorizing tests using build flags, environment variables, or short mode makes the testing process more efficient. You can create test categories using build flags or environment variables (for example, unit versus integration tests) and differentiate short from long-running tests to decide which kinds of tests to execute.
Source code
"},{"location":"#not-enabling-the-race-flag-83","title":"Not enabling the race flag (#83)","text":"TL;DREnabling the -race
flag is highly recommended when writing concurrent applications. Doing so allows you to catch potential data races that can lead to software bugs.
Using the -parallel
flag is an efficient way to speed up tests, especially long-running ones. Use the -shuffle
flag to help ensure that a test suite doesn\u2019t rely on wrong assumptions that could hide bugs.
Table-driven tests are an efficient way to group a set of similar tests to prevent code duplication and make future updates easier to handle.
Source code
"},{"location":"#sleeping-in-unit-tests-86","title":"Sleeping in unit tests (#86)","text":"TL;DRAvoid sleeps using synchronization to make a test less flaky and more robust. If synchronization isn\u2019t possible, consider a retry approach.
Source code
"},{"location":"#not-dealing-with-the-time-api-efficiently-87","title":"Not dealing with the time API efficiently (#87)","text":"TL;DRUnderstanding how to deal with functions using the time API is another way to make a test less flaky. You can use standard techniques such as handling the time as part of a hidden dependency or asking clients to provide it.
Source code
"},{"location":"#not-using-testing-utility-packages-httptest-and-iotest-88","title":"Not using testing utility packages (httptest
and iotest
) (#88)","text":"httptest
package is helpful for dealing with HTTP applications. It provides a set of utilities to test both clients and servers.Source code
iotest
package helps write io.Reader and test that an application is tolerant to errors.Source code
"},{"location":"#writing-inaccurate-benchmarks-89","title":"Writing inaccurate benchmarks (#89)","text":"TL;DRRegarding benchmarks:
Read the full section here.
Source code
"},{"location":"#not-exploring-all-the-go-testing-features-90","title":"Not exploring all the Go testing features (#90)","text":"Use code coverage with the -coverprofile
flag to quickly see which part of the code needs more attention.
Place unit tests in a different package to enforce writing tests that focus on an exposed behavior, not internals.
Source code
Handling errors using the *testing.T
variable instead of the classic if err != nil
makes code shorter and easier to read.
Source code
You can use setup and teardown functions to configure a complex environment, such as in the case of integration tests.
Source code
"},{"location":"#not-using-fuzzing-community-mistake","title":"Not using fuzzing (community mistake)","text":"TL;DRFuzzing is an efficient strategy to detect random, unexpected, or malformed inputs to complex functions and methods in order to discover vulnerabilities, bugs, or even potential crashes.
Credits: @jeromedoucet
"},{"location":"#optimizations","title":"Optimizations","text":""},{"location":"#not-understanding-cpu-caches-91","title":"Not understanding CPU caches (#91)","text":"Understanding how to use CPU caches is important for optimizing CPU-bound applications because the L1 cache is about 50 to 100 times faster than the main memory.
Being conscious of the cache line concept is critical to understanding how to organize data in data-intensive applications. A CPU doesn\u2019t fetch memory word by word; instead, it usually copies a memory block to a 64-byte cache line. To get the most out of each individual cache line, enforce spatial locality.
Source code
Source code
Making code predictable for the CPU can also be an efficient way to optimize certain functions. For example, a unit or constant stride is predictable for the CPU, but a non-unit stride (for example, a linked list) isn\u2019t predictable.
Source code
To avoid a critical stride, hence utilizing only a tiny portion of the cache, be aware that caches are partitioned.
"},{"location":"#writing-concurrent-code-that-leads-to-false-sharing-92","title":"Writing concurrent code that leads to false sharing (#92)","text":"TL;DRKnowing that lower levels of CPU caches aren\u2019t shared across all the cores helps avoid performance-degrading patterns such as false sharing while writing concurrency code. Sharing memory is an illusion.
Read the full section here.
Source code
"},{"location":"#not-taking-into-account-instruction-level-parallelism-93","title":"Not taking into account instruction-level parallelism (#93)","text":"TL;DRUse instruction-level parallelism (ILP) to optimize specific parts of your code to allow a CPU to execute as many parallel instructions as possible. Identifying data hazards is one of the main steps.
Source code
"},{"location":"#not-being-aware-of-data-alignment-94","title":"Not being aware of data alignment (#94)","text":"TL;DRYou can avoid common mistakes by remembering that in Go, basic types are aligned with their own size. For example, keep in mind that reorganizing the fields of a struct by size in descending order can lead to more compact structs (less memory allocation and potentially a better spatial locality).
Source code
"},{"location":"#not-understanding-stack-vs-heap-95","title":"Not understanding stack vs. heap (#95)","text":"TL;DRUnderstanding the fundamental differences between heap and stack should also be part of your core knowledge when optimizing a Go application. Stack allocations are almost free, whereas heap allocations are slower and rely on the GC to clean the memory.
Source code
"},{"location":"#not-knowing-how-to-reduce-allocations-api-change-compiler-optimizations-and-syncpool-96","title":"Not knowing how to reduce allocations (API change, compiler optimizations, andsync.Pool
) (#96)","text":"TL;DR Reducing allocations is also an essential aspect of optimizing a Go application. This can be done in different ways, such as designing the API carefully to prevent sharing up, understanding the common Go compiler optimizations, and using sync.Pool
.
Source code
"},{"location":"#not-relying-on-inlining-97","title":"Not relying on inlining (#97)","text":"TL;DRUse the fast-path inlining technique to efficiently reduce the amortized time to call a function.
"},{"location":"#not-using-go-diagnostics-tooling-98","title":"Not using Go diagnostics tooling (#98)","text":"TL;DRRely on profiling and the execution tracer to understand how an application performs and the parts to optimize.
Read the full section here.
"},{"location":"#not-understanding-how-the-gc-works-99","title":"Not understanding how the GC works (#99)","text":"TL;DRUnderstanding how to tune the GC can lead to multiple benefits such as handling sudden load increases more efficiently.
"},{"location":"#not-understanding-the-impacts-of-running-go-in-docker-and-kubernetes-100","title":"Not understanding the impacts of running Go in Docker and Kubernetes (#100)","text":"TL;DRTo help avoid CPU throttling when deployed in Docker and Kubernetes, keep in mind that Go isn\u2019t CFS-aware.
The GOMAXPROCS
variable defines the limit of OS threads in charge of executing user-level code simultaneously. By default, it's set to the number of OS-apparent logical CPU cores.
When running some Go code inside Docker and Kubernetes, we must know that Go isn't CFS-aware (github.com/golang/go/issues/33803). Therefore, GOMAXPROCS
isn't automatically set to the value of spec.containers.resources.limits.cpu
(see Kubernetes Resource Management for Pods and Containers); instead, it's set to the number of logical cores on the host machine. The main implication is that it can lead to an increased tail latency in some specific situations.
One solution is to rely on uber-go/automaxprocs that automatically set GOMAXPROCS
to match the Linux container CPU quota.
Thanks to all the contributors:
"},{"location":"20-slice/","title":"Not understanding slice length and capacity","text":"
It\u2019s pretty common for Go developers to mix slice length and capacity or not understand them thoroughly. Assimilating these two concepts is essential for efficiently handling core operations such as slice initialization and adding elements with append, copying, or slicing. This misunderstanding can lead to using slices suboptimally or even to memory leaks.
In Go, a slice is backed by an array. That means the slice\u2019s data is stored contiguously in an array data structure. A slice also handles the logic of adding an element if the backing array is full or shrinking the backing array if it\u2019s almost empty.
Internally, a slice holds a pointer to the backing array plus a length and a capacity. The length is the number of elements the slice contains, whereas the capacity is the number of elements in the backing array, counting from the first element in the slice. Let\u2019s go through a few examples to make things clearer. First, let\u2019s initialize a slice with a given length and capacity:
s := make([]int, 3, 6) // Three-length, six-capacity slice\n
The first argument, representing the length, is mandatory. However, the second argument representing the capacity is optional. Figure 1 shows the result of this code in memory.
Figure 1: A three-length, six-capacity slice.
In this case, make
creates an array of six elements (the capacity). But because the length was set to 3, Go initializes only the first three elements. Also, because the slice is an []int
type, the first three elements are initialized to the zeroed value of an int
: 0. The grayed elements are allocated but not yet used.
If we print this slice, we get the elements within the range of the length, [0 0 0]
. If we set s[1]
to 1, the second element of the slice updates without impacting its length or capacity. Figure 2 illustrates this.
Figure 2: Updating the slice\u2019s second element: s[1] = 1.
However, accessing an element outside the length range is forbidden, even though it\u2019s already allocated in memory. For example, s[4]
= 0 would lead to the following panic:
panic: runtime error: index out of range [4] with length 3\n
How can we use the remaining space of the slice? By using the append
built-in function:
s = append(s, 2)\n
This code appends to the existing s
slice a new element. It uses the first grayed element (which was allocated but not yet used) to store element 2, as figure 3 shows.
Figure 3: Appending an element to s.
The length of the slice is updated from 3 to 4 because the slice now contains four elements. Now, what happens if we add three more elements so that the backing array isn\u2019t large enough?
s = append(s, 3, 4, 5)\nfmt.Println(s)\n
If we run this code, we see that the slice was able to cope with our request:
[0 1 0 2 3 4 5]\n
Because an array is a fixed-size structure, it can store the new elements until element 4. When we want to insert element 5, the array is already full: Go internally creates another array by doubling the capacity, copying all the elements, and then inserting element 5. Figure 4 shows this process.
Figure 4: Because the initial backing array is full, Go creates another array and copies all the elements.
The slice now references the new backing array. What will happen to the previous backing array? If it\u2019s no longer referenced, it\u2019s eventually freed by the garbage collector (GC) if allocated on the heap. (We discuss heap memory in mistake #95, \u201cNot understanding stack vs. heap,\u201d and we look at how the GC works in mistake #99, \u201cNot understanding how the GC works.\u201d)
What happens with slicing? Slicing is an operation done on an array or a slice, providing a half-open range; the first index is included, whereas the second is excluded. The following example shows the impact, and figure 5 displays the result in memory:
s1 := make([]int, 3, 6) // Three-length, six-capacity slice\ns2 := s1[1:3] // Slicing from indices 1 to 3\n
Figure 5: The slices s1 and s2 reference the same backing array with different lengths and capacities.
First, s1
is created as a three-length, six-capacity slice. When s2
is created by slicing s1
, both slices reference the same backing array. However, s2
starts from a different index, 1. Therefore, its length and capacity (a two-length, five-capacity slice) differ from s1. If we update s1[1]
or s2[0]
, the change is made to the same array, hence, visible in both slices, as figure 6 shows.
Figure 6: Because s1 and s2 are backed by the same array, updating a common element makes the change visible in both slices.
Now, what happens if we append an element to s2
? Does the following code change s1
as well?
s2 = append(s2, 2)\n
The shared backing array is modified, but only the length of s2
changes. Figure 7 shows the result of appending an element to s2
.
Figure 7: Appending an element to s2.
s1
remains a three-length, six-capacity slice. Therefore, if we print s1
and s2
, the added element is only visible for s2
:
s1=[0 1 0], s2=[1 0 2]\n
It\u2019s important to understand this behavior so that we don\u2019t make wrong assumptions while using append.
NoteIn these examples, the backing array is internal and not available directly to the Go developer. The only exception is when a slice is created from slicing an existing array.
One last thing to note: what if we keep appending elements to s2
until the backing array is full? What will the state be, memory-wise? Let\u2019s add three more elements so that the backing array will not have enough capacity:
s2 = append(s2, 3)\ns2 = append(s2, 4) // At this stage, the backing is already full\ns2 = append(s2, 5)\n
This code leads to creating another backing array. Figure 8 displays the results in memory.
Figure 8: Appending elements to s2 until the backing array is full.
s1
and s2
now reference two different arrays. As s1
is still a three-length, six-capacity slice, it still has some available buffer, so it keeps referencing the initial array. Also, the new backing array was made by copying the initial one from the first index of s2
. That\u2019s why the new array starts with element 1, not 0.
To summarize, the slice length is the number of available elements in the slice, whereas the slice capacity is the number of elements in the backing array. Adding an element to a full slice (length == capacity) leads to creating a new backing array with a new capacity, copying all the elements from the previous array, and updating the slice pointer to the new array.
"},{"location":"28-maps-memory-leaks/","title":"Maps and memory leaks","text":"When working with maps in Go, we need to understand some important characteristics of how a map grows and shrinks. Let\u2019s delve into this to prevent issues that can cause memory leaks.
First, to view a concrete example of this problem, let\u2019s design a scenario where we will work with the following map:
m := make(map[int][128]byte)\n
Each value of m is an array of 128 bytes. We will do the following:
After each step, we want to print the size of the heap (using a printAlloc
utility function). This shows us how this example behaves memory-wise:
func main() {\n n := 1_000_000\n m := make(map[int][128]byte)\n printAlloc()\n\n for i := 0; i < n; i++ { // Adds 1 million elements\n m[i] = [128]byte{}\n }\n printAlloc()\n\n for i := 0; i < n; i++ { // Deletes 1 million elements\n delete(m, i)\n }\n\n runtime.GC() // Triggers a manual GC\n printAlloc()\n runtime.KeepAlive(m) // Keeps a reference to m so that the map isn\u2019t collected\n}\n\nfunc printAlloc() {\n var m runtime.MemStats\n runtime.ReadMemStats(&m)\n fmt.Printf(\"%d MB\\n\", m.Alloc/(1024*1024))\n}\n
We allocate an empty map, add 1 million elements, remove 1 million elements, and then run a GC. We also make sure to keep a reference to the map using runtime.KeepAlive
so that the map isn\u2019t collected as well. Let\u2019s run this example:
0 MB <-- After m is allocated\n461 MB <-- After we add 1 million elements\n293 MB <-- After we remove 1 million elements\n
What can we observe? At first, the heap size is minimal. Then it grows significantly after having added 1 million elements to the map. But if we expected the heap size to decrease after removing all the elements, this isn\u2019t how maps work in Go. In the end, even though the GC has collected all the elements, the heap size is still 293 MB. So the memory shrunk, but not as we might have expected. What\u2019s the rationale? We need to delve into how a map works in Go.
A map provides an unordered collection of key-value pairs in which all the keys are distinct. In Go, a map is based on the hash table data structure: an array where each element is a pointer to a bucket of key-value pairs, as shown in figure 1.
Figure 1: A hash table example with a focus on bucket 0.
Each bucket is a fixed-size array of eight elements. In the case of an insertion into a bucket that is already full (a bucket overflow), Go creates another bucket of eight elements and links the previous one to it. Figure 2 shows an example:
Figure 2: In case of a bucket overflow, Go allocates a new bucket and links the previous bucket to it.
Under the hood, a Go map is a pointer to a runtime.hmap struct. This struct contains multiple fields, including a B field, giving the number of buckets in the map:
type hmap struct {\n B uint8 // log_2 of # of buckets\n // (can hold up to loadFactor * 2^B items)\n // ...\n}\n
After adding 1 million elements, the value of B equals 18, which means 2\u00b9\u2078 = 262,144 buckets. When we remove 1 million elements, what\u2019s the value of B? Still 18. Hence, the map still contains the same number of buckets.
The reason is that the number of buckets in a map cannot shrink. Therefore, removing elements from a map doesn\u2019t impact the number of existing buckets; it just zeroes the slots in the buckets. A map can only grow and have more buckets; it never shrinks.
In the previous example, we went from 461 MB to 293 MB because the elements were collected, but running the GC didn\u2019t impact the map itself. Even the number of extra buckets (the buckets created because of overflows) remains the same.
Let\u2019s take a step back and discuss when the fact that a map cannot shrink can be a problem. Imagine building a cache using a map[int][128]byte
. This map holds per customer ID (the int
), a sequence of 128 bytes. Now, suppose we want to save the last 1,000 customers. The map size will remain constant, so we shouldn\u2019t worry about the fact that a map cannot shrink.
However, let\u2019s say we want to store one hour of data. Meanwhile, our company has decided to have a big promotion for Black Friday: in one hour, we may have millions of customers connected to our system. But a few days after Black Friday, our map will contain the same number of buckets as during the peak time. This explains why we can experience high memory consumption that doesn\u2019t significantly decrease in such a scenario.
What are the solutions if we don\u2019t want to manually restart our service to clean the amount of memory consumed by the map? One solution could be to re-create a copy of the current map at a regular pace. For example, every hour, we can build a new map, copy all the elements, and release the previous one. The main drawback of this option is that following the copy and until the next garbage collection, we may consume twice the current memory for a short period.
Another solution would be to change the map type to store an array pointer: map[int]*[128]byte
. It doesn\u2019t solve the fact that we will have a significant number of buckets; however, each bucket entry will reserve the size of a pointer for the value instead of 128 bytes (8 bytes on 64-bit systems and 4 bytes on 32-bit systems).
Coming back to the original scenario, let\u2019s compare the memory consumption for each map type following each step. The following table shows the comparison.
Stepmap[int][128]byte
map[int]*[128]byte
Allocate an empty map 0 MB 0 MB Add 1 million elements 461 MB 182 MB Remove all the elements and run a GC 293 MB 38 MB Note If a key or a value is over 128 bytes, Go won\u2019t store it directly in the map bucket. Instead, Go stores a pointer to reference the key or the value.
As we have seen, adding n elements to a map and then deleting all the elements means keeping the same number of buckets in memory. So, we must remember that because a Go map can only grow in size, so does its memory consumption. There is no automated strategy to shrink it. If this leads to high memory consumption, we can try different options such as forcing Go to re-create the map or using pointers to check if it can be optimized.
"},{"location":"5-interface-pollution/","title":"Interface pollution","text":"Interfaces are one of the cornerstones of the Go language when designing and structuring our code. However, like many tools or concepts, abusing them is generally not a good idea. Interface pollution is about overwhelming our code with unnecessary abstractions, making it harder to understand. It\u2019s a common mistake made by developers coming from another language with different habits. Before delving into the topic, let\u2019s refresh our minds about Go\u2019s interfaces. Then, we will see when it\u2019s appropriate to use interfaces and when it may be considered pollution.
"},{"location":"5-interface-pollution/#concepts","title":"Concepts","text":"An interface provides a way to specify the behavior of an object. We use interfaces to create common abstractions that multiple objects can implement. What makes Go interfaces so different is that they are satisfied implicitly. There is no explicit keyword like implements
to mark that an object X implements interface Y.
To understand what makes interfaces so powerful, we will dig into two popular ones from the standard library: io.Reader
and io.Writer
. The io
package provides abstractions for I/O primitives. Among these abstractions, io.Reader
relates to reading data from a data source and io.Writer
to writing data to a target, as represented in the next figure:
The io.Reader
contains a single Read method:
type Reader interface {\n Read(p []byte) (n int, err error)\n}\n
Custom implementations of the io.Reader
interface should accept a slice of bytes, filling it with its data and returning either the number of bytes read or an error.
On the other hand, io.Writer
defines a single method, Write:
type Writer interface {\n Write(p []byte) (n int, err error)\n}\n
Custom implementations of io.Writer
should write the data coming from a slice to a target and return either the number of bytes written or an error. Therefore, both interfaces provide fundamental abstractions:
io.Reader
reads data from a sourceio.Writer
writes data to a targetWhat is the rationale for having these two interfaces in the language? What is the point of creating these abstractions?
Let\u2019s assume we need to implement a function that should copy the content of one file to another. We could create a specific function that would take as input two *os.Files
. Or, we can choose to create a more generic function using io.Reader
and io.Writer
abstractions:
func copySourceToDest(source io.Reader, dest io.Writer) error {\n // ...\n}\n
This function would work with *os.File
parameters (as *os.File
implements both io.Reader
and io.Writer
) and any other type that would implement these interfaces. For example, we could create our own io.Writer
that writes to a database, and the code would remain the same. It increases the genericity of the function; hence, its reusability.
Furthermore, writing a unit test for this function is easier because, instead of having to handle files, we can use the strings
and bytes
packages that provide helpful implementations:
func TestCopySourceToDest(t *testing.T) {\n const input = \"foo\"\n source := strings.NewReader(input) // Creates an io.Reader\n dest := bytes.NewBuffer(make([]byte, 0)) // Creates an io.Writer\n\n err := copySourceToDest(source, dest) // Calls copySourceToDest from a *strings.Reader and a *bytes.Buffer\n if err != nil {\n t.FailNow()\n }\n\n got := dest.String()\n if got != input {\n t.Errorf(\"expected: %s, got: %s\", input, got)\n }\n}\n
In the example, source is a *strings.Reader
, whereas dest is a *bytes.Buffer
. Here, we test the behavior of copySourceToDest
without creating any files.
While designing interfaces, the granularity (how many methods the interface contains) is also something to keep in mind. A known proverb in Go relates to how big an interface should be:
Rob Pike
The bigger the interface, the weaker the abstraction.
Indeed, adding methods to an interface can decrease its level of reusability. io.Reader
and io.Writer
are powerful abstractions because they cannot get any simpler. Furthermore, we can also combine fine-grained interfaces to create higher-level abstractions. This is the case with io.ReadWriter
, which combines the reader and writer behaviors:
type ReadWriter interface {\n Reader\n Writer\n}\n
Note As Einstein said, \u201cEverything should be made as simple as possible, but no simpler.\u201d Applied to interfaces, this denotes that finding the perfect granularity for an interface isn\u2019t necessarily a straightforward process.
Let\u2019s now discuss common cases where interfaces are recommended.
"},{"location":"5-interface-pollution/#when-to-use-interfaces","title":"When to use interfaces","text":"When should we create interfaces in Go? Let\u2019s look at three concrete use cases where interfaces are usually considered to bring value. Note that the goal isn\u2019t to be exhaustive because the more cases we add, the more they would depend on the context. However, these three cases should give us a general idea:
The first option we will discuss is to use interfaces when multiple types implement a common behavior. In such a case, we can factor out the behavior inside an interface. If we look at the standard library, we can find many examples of such a use case. For example, sorting a collection can be factored out via three methods:
Hence, the following interface was added to the sort
package:
type Interface interface {\n Len() int // Number of elements\n Less(i, j int) bool // Checks two elements\n Swap(i, j int) // Swaps two elements\n}\n
This interface has a strong potential for reusability because it encompasses the common behavior to sort any collection that is index-based.
Throughout the sort
package, we can find dozens of implementations. If at some point we compute a collection of integers, for example, and we want to sort it, are we necessarily interested in the implementation type? Is it important whether the sorting algorithm is a merge sort or a quicksort? In many cases, we don\u2019t care. Hence, the sorting behavior can be abstracted, and we can depend on the sort.Interface
.
Finding the right abstraction to factor out a behavior can also bring many benefits. For example, the sort
package provides utility functions that also rely on sort.Interface
, such as checking whether a collection is already sorted. For instance:
func IsSorted(data Interface) bool {\n n := data.Len()\n for i := n - 1; i > 0; i-- {\n if data.Less(i, i-1) {\n return false\n }\n }\n return true\n}\n
Because sort.Interface
is the right level of abstraction, it makes it highly valuable.
Let\u2019s now see another main use case when using interfaces.
"},{"location":"5-interface-pollution/#decoupling","title":"Decoupling","text":"Another important use case is about decoupling our code from an implementation. If we rely on an abstraction instead of a concrete implementation, the implementation itself can be replaced with another without even having to change our code. This is the Liskov Substitution Principle (the L in Robert C. Martin\u2019s SOLID design principles).
One benefit of decoupling can be related to unit testing. Let\u2019s assume we want to implement a CreateNewCustomer
method that creates a new customer and stores it. We decide to rely on the concrete implementation directly (let\u2019s say a mysql.Store
struct):
type CustomerService struct {\n store mysql.Store // Depends on the concrete implementation\n}\n\nfunc (cs CustomerService) CreateNewCustomer(id string) error {\n customer := Customer{id: id}\n return cs.store.StoreCustomer(customer)\n}\n
Now, what if we want to test this method? Because customerService
relies on the actual implementation to store a Customer
, we are obliged to test it through integration tests, which requires spinning up a MySQL instance (unless we use an alternative technique such as go-sqlmock
, but this isn\u2019t the scope of this section). Although integration tests are helpful, that\u2019s not always what we want to do. To give us more flexibility, we should decouple CustomerService
from the actual implementation, which can be done via an interface like so:
type customerStorer interface { // Creates a storage abstraction\n StoreCustomer(Customer) error\n}\n\ntype CustomerService struct {\n storer customerStorer // Decouples CustomerService from the actual implementation\n}\n\nfunc (cs CustomerService) CreateNewCustomer(id string) error {\n customer := Customer{id: id}\n return cs.storer.StoreCustomer(customer)\n}\n
Because storing a customer is now done via an interface, this gives us more flexibility in how we want to test the method. For instance, we can:
Let\u2019s now discuss another use case: to restrict a behavior.
"},{"location":"5-interface-pollution/#restricting-behavior","title":"Restricting behavior","text":"The last use case we will discuss can be pretty counterintuitive at first sight. It\u2019s about restricting a type to a specific behavior. Let\u2019s imagine we implement a custom configuration package to deal with dynamic configuration. We create a specific container for int
configurations via an IntConfig
struct that also exposes two methods: Get
and Set
. Here\u2019s how that code would look:
type IntConfig struct {\n // ...\n}\n\nfunc (c *IntConfig) Get() int {\n // Retrieve configuration\n}\n\nfunc (c *IntConfig) Set(value int) {\n // Update configuration\n}\n
Now, suppose we receive an IntConfig
that holds some specific configuration, such as a threshold. Yet, in our code, we are only interested in retrieving the configuration value, and we want to prevent updating it. How can we enforce that, semantically, this configuration is read-only, if we don\u2019t want to change our configuration package? By creating an abstraction that restricts the behavior to retrieving only a config value:
type intConfigGetter interface {\n Get() int\n}\n
Then, in our code, we can rely on intConfigGetter
instead of the concrete implementation:
type Foo struct {\n threshold intConfigGetter\n}\n\nfunc NewFoo(threshold intConfigGetter) Foo { // Injects the configuration getter\n return Foo{threshold: threshold}\n}\n\nfunc (f Foo) Bar() {\n threshold := f.threshold.Get() // Reads the configuration\n // ...\n}\n
In this example, the configuration getter is injected into the NewFoo
factory method. It doesn\u2019t impact a client of this function because it can still pass an IntConfig
struct as it implements intConfigGetter
. Then, we can only read the configuration in the Bar
method, not modify it. Therefore, we can also use interfaces to restrict a type to a specific behavior for various reasons, such as semantics enforcement.
In this section, we saw three potential use cases where interfaces are generally considered as bringing value: factoring out a common behavior, creating some decoupling, and restricting a type to a certain behavior. Again, this list isn\u2019t exhaustive, but it should give us a general understanding of when interfaces are helpful in Go.
Now, let\u2019s finish this section and discuss the problems with interface pollution.
"},{"location":"5-interface-pollution/#interface-pollution_1","title":"Interface pollution","text":"It\u2019s fairly common to see interfaces being overused in Go projects. Perhaps the developer\u2019s background was C# or Java, and they found it natural to create interfaces before concrete types. However, this isn\u2019t how things should work in Go.
As we discussed, interfaces are made to create abstractions. And the main caveat when programming meets abstractions is remembering that abstractions should be discovered, not created. What does this mean? It means we shouldn\u2019t start creating abstractions in our code if there is no immediate reason to do so. We shouldn\u2019t design with interfaces but wait for a concrete need. Said differently, we should create an interface when we need it, not when we foresee that we could need it.
What\u2019s the main problem if we overuse interfaces? The answer is that they make the code flow more complex. Adding a useless level of indirection doesn\u2019t bring any value; it creates a worthless abstraction making the code more difficult to read, understand, and reason about. If we don\u2019t have a strong reason for adding an interface and it\u2019s unclear how an interface makes a code better, we should challenge this interface\u2019s purpose. Why not call the implementation directly?
NoteWe may also experience performance overhead when calling a method through an interface. It requires a lookup in a hash table\u2019s data structure to find the concrete type an interface points to. But this isn\u2019t an issue in many contexts as the overhead is minimal.
In summary, we should be cautious when creating abstractions in our code\u2014abstractions should be discovered, not created. It\u2019s common for us, software developers, to overengineer our code by trying to guess what the perfect level of abstraction is, based on what we think we might need later. This process should be avoided because, in most cases, it pollutes our code with unnecessary abstractions, making it more complex to read.
Rob Pike
Don\u2019t design with interfaces, discover them.
Let\u2019s not try to solve a problem abstractly but solve what has to be solved now. Last, but not least, if it\u2019s unclear how an interface makes the code better, we should probably consider removing it to make our code simpler.
"},{"location":"56-concurrency-faster/","title":"Thinking concurrency is always faster","text":"A misconception among many developers is believing that a concurrent solution is always faster than a sequential one. This couldn\u2019t be more wrong. The overall performance of a solution depends on many factors, such as the efficiency of our code structure (concurrency), which parts can be tackled in parallel, and the level of contention among the computation units. This post reminds us about some fundamental knowledge of concurrency in Go; then we will see a concrete example where a concurrent solution isn\u2019t necessarily faster.
"},{"location":"56-concurrency-faster/#go-scheduling","title":"Go Scheduling","text":"A thread is the smallest unit of processing that an OS can perform. If a process wants to execute multiple actions simultaneously, it spins up multiple threads. These threads can be:
The OS is responsible for scheduling the thread\u2019s processes optimally so that:
The word thread can also have a different meaning at a CPU level. Each physical core can be composed of multiple logical cores (the concept of hyper-threading), and a logical core is also called a thread. In this post, when we use the word thread, we mean the unit of processing, not a logical core.
A CPU core executes different threads. When it switches from one thread to another, it executes an operation called context switching. The active thread consuming CPU cycles was in an executing state and moves to a runnable state, meaning it\u2019s ready to be executed pending an available core. Context switching is considered an expensive operation because the OS needs to save the current execution state of a thread before the switch (such as the current register values).
As Go developers, we can\u2019t create threads directly, but we can create goroutines, which can be thought of as application-level threads. However, whereas an OS thread is context-switched on and off a CPU core by the OS, a goroutine is context-switched on and off an OS thread by the Go runtime. Also, compared to an OS thread, a goroutine has a smaller memory footprint: 2 KB for goroutines from Go 1.4. An OS thread depends on the OS, but, for example, on Linux/x86\u201332, the default size is 2 MB (see https://man7.org/linux/man-pages/man3/pthread_create.3.html). Having a smaller size makes context switching faster.
NoteContext switching a goroutine versus a thread is about 80% to 90% faster, depending on the architecture.
Let\u2019s now discuss how the Go scheduler works to overview how goroutines are handled. Internally, the Go scheduler uses the following terminology (see proc.go):
Each OS thread (M) is assigned to a CPU core (P) by the OS scheduler. Then, each goroutine (G) runs on an M. The GOMAXPROCS variable defines the limit of Ms in charge of executing user-level code simultaneously. But if a thread is blocked in a system call (for example, I/O), the scheduler can spin up more Ms. As of Go 1.5, GOMAXPROCS is by default equal to the number of available CPU cores.
A goroutine has a simpler lifecycle than an OS thread. It can be doing one of the following:
There\u2019s one last stage to understand about the implementation of Go scheduling: when a goroutine is created but cannot be executed yet; for example, all the other Ms are already executing a G. In this scenario, what will the Go runtime do about it? The answer is queuing. The Go runtime handles two kinds of queues: one local queue per P and a global queue shared among all the Ps.
Figure 1 shows a given scheduling situation on a four-core machine with GOMAXPROCS equal to 4. The parts are the logical cores (Ps), goroutines (Gs), OS threads (Ms), local queues, and global queue:
Figure 1: An example of the current state of a Go application executed on a four-core machine. Goroutines that aren\u2019t in an executing state are either runnable (pending being executed) or waiting (pending a blocking operation)
First, we can see five Ms, whereas GOMAXPROCS is set to 4. But as we mentioned, if needed, the Go runtime can create more OS threads than the GOMAXPROCS value.
P0, P1, and P3 are currently busy executing Go runtime threads. But P2 is presently idle as M3 is switched off P2, and there\u2019s no goroutine to be executed. This isn\u2019t a good situation because six runnable goroutines are pending being executed, some in the global queue and some in other local queues. How will the Go runtime handle this situation? Here\u2019s the scheduling implementation in pseudocode (see proc.go):
runtime.schedule() {\n // Only 1/61 of the time, check the global runnable queue for a G.\n // If not found, check the local queue.\n // If not found,\n // Try to steal from other Ps.\n // If not, check the global runnable queue.\n // If not found, poll network.\n}\n
Every sixty-first execution, the Go scheduler will check whether goroutines from the global queue are available. If not, it will check its local queue. Meanwhile, if both the global and local queues are empty, the Go scheduler can pick up goroutines from other local queues. This principle in scheduling is called work stealing, and it allows an underutilized processor to actively look for another processor\u2019s goroutines and steal some.
One last important thing to mention: prior to Go 1.14, the scheduler was cooperative, which meant a goroutine could be context-switched off a thread only in specific blocking cases (for example, channel send or receive, I/O, waiting to acquire a mutex). Since Go 1.14, the Go scheduler is now preemptive: when a goroutine is running for a specific amount of time (10 ms), it will be marked preemptible and can be context-switched off to be replaced by another goroutine. This allows a long-running job to be forced to share CPU time.
Now that we understand the fundamentals of scheduling in Go, let\u2019s look at a concrete example: implementing a merge sort in a parallel manner.
"},{"location":"56-concurrency-faster/#parallel-merge-sort","title":"Parallel Merge Sort","text":"First, let\u2019s briefly review how the merge sort algorithm works. Then we will implement a parallel version. Note that the objective isn\u2019t to implement the most efficient version but to support a concrete example showing why concurrency isn\u2019t always faster.
The merge sort algorithm works by breaking a list repeatedly into two sublists until each sublist consists of a single element and then merging these sublists so that the result is a sorted list (see figure 2). Each split operation splits the list into two sublists, whereas the merge operation merges two sublists into a sorted list.
Figure 2: Applying the merge sort algorithm repeatedly breaks each list into two sublists. Then the algorithm uses a merge operation such that the resulting list is sorted
Here is the sequential implementation of this algorithm. We don\u2019t include all of the code as it\u2019s not the main point of this section:
func sequentialMergesort(s []int) {\n if len(s) <= 1 {\n return\n }\n\n middle := len(s) / 2\n sequentialMergesort(s[:middle]) // First half\n sequentialMergesort(s[middle:]) // Second half\n merge(s, middle) // Merges the two halves\n}\n\nfunc merge(s []int, middle int) {\n // ...\n}\n
This algorithm has a structure that makes it open to concurrency. Indeed, as each sequentialMergesort operation works on an independent set of data that doesn\u2019t need to be fully copied (here, an independent view of the underlying array using slicing), we could distribute this workload among the CPU cores by spinning up each sequentialMergesort operation in a different goroutine. Let\u2019s write a first parallel implementation:
func parallelMergesortV1(s []int) {\n if len(s) <= 1 {\n return\n }\n\n middle := len(s) / 2\n\n var wg sync.WaitGroup\n wg.Add(2)\n\n go func() { // Spins up the first half of the work in a goroutine\n defer wg.Done()\n parallelMergesortV1(s[:middle])\n }()\n\n go func() { // Spins up the second half of the work in a goroutine\n defer wg.Done()\n parallelMergesortV1(s[middle:])\n }()\n\n wg.Wait()\n merge(s, middle) // Merges the halves\n}\n
In this version, each half of the workload is handled in a separate goroutine. The parent goroutine waits for both parts by using sync.WaitGroup. Hence, we call the Wait method before the merge operation.
We now have a parallel version of the merge sort algorithm. Therefore, if we run a benchmark to compare this version against the sequential one, the parallel version should be faster, correct? Let\u2019s run it on a four-core machine with 10,000 elements:
Benchmark_sequentialMergesort-4 2278993555 ns/op\nBenchmark_parallelMergesortV1-4 17525998709 ns/op\n
Surprisingly, the parallel version is almost an order of magnitude slower. How can we explain this result? How is it possible that a parallel version that distributes a workload across four cores is slower than a sequential version running on a single machine? Let\u2019s analyze the problem.
If we have a slice of, say, 1,024 elements, the parent goroutine will spin up two goroutines, each in charge of handling a half consisting of 512 elements. Each of these goroutines will spin up two new goroutines in charge of handling 256 elements, then 128, and so on, until we spin up a goroutine to compute a single element.
If the workload that we want to parallelize is too small, meaning we\u2019re going to compute it too fast, the benefit of distributing a job across cores is destroyed: the time it takes to create a goroutine and have the scheduler execute it is much too high compared to directly merging a tiny number of items in the current goroutine. Although goroutines are lightweight and faster to start than threads, we can still face cases where a workload is too small.
So what can we conclude from this result? Does it mean the merge sort algorithm cannot be parallelized? Wait, not so fast.
Let\u2019s try another approach. Because merging a tiny number of elements within a new goroutine isn\u2019t efficient, let\u2019s define a threshold. This threshold will represent how many elements a half should contain in order to be handled in a parallel manner. If the number of elements in the half is fewer than this value, we will handle it sequentially. Here\u2019s a new version:
const max = 2048 // Defines the threshold\n\nfunc parallelMergesortV2(s []int) {\n if len(s) <= 1 {\n return\n }\n\n if len(s) <= max {\n sequentialMergesort(s) // Calls our initial sequential version\n } else { // If bigger than the threshold, keeps the parallel version\n middle := len(s) / 2\n\n var wg sync.WaitGroup\n wg.Add(2)\n\n go func() {\n defer wg.Done()\n parallelMergesortV2(s[:middle])\n }()\n\n go func() {\n defer wg.Done()\n parallelMergesortV2(s[middle:])\n }()\n\n wg.Wait()\n merge(s, middle)\n }\n}\n
If the number of elements in the s slice is smaller than max, we call the sequential version. Otherwise, we keep calling our parallel implementation. Does this approach impact the result? Yes, it does:
Benchmark_sequentialMergesort-4 2278993555 ns/op\nBenchmark_parallelMergesortV1-4 17525998709 ns/op\nBenchmark_parallelMergesortV2-4 1313010260 ns/op\n
Our v2 parallel implementation is more than 40% faster than the sequential one, thanks to this idea of defining a threshold to indicate when parallel should be more efficient than sequential.
NoteWhy did I set the threshold to 2,048? Because it was the optimal value for this specific workload on my machine. In general, such magic values should be defined carefully with benchmarks (running on an execution environment similar to production). It\u2019s also pretty interesting to note that running the same algorithm in a programming language that doesn\u2019t implement the concept of goroutines has an impact on the value. For example, running the same example in Java using threads means an optimal value closer to 8,192. This tends to illustrate how goroutines are more efficient than threads.
"},{"location":"56-concurrency-faster/#conclusion","title":"Conclusion","text":"We have seen throughout this post the fundamental concepts of scheduling in Go: the differences between a thread and a goroutine and how the Go runtime schedules goroutines. Meanwhile, using the parallel merge sort example, we illustrated that concurrency isn\u2019t always necessarily faster. As we have seen, spinning up goroutines to handle minimal workloads (merging only a small set of elements) demolishes the benefit we could get from parallelism.
So, where should we go from here? We must keep in mind that concurrency isn\u2019t always faster and shouldn\u2019t be considered the default way to go for all problems. First, it makes things more complex. Also, modern CPUs have become incredibly efficient at executing sequential code and predictable code. For example, a superscalar processor can parallelize instruction execution over a single core with high efficiency.
Does this mean we shouldn\u2019t use concurrency? Of course not. However, it\u2019s essential to keep these conclusions in mind. If we\u2019re not sure that a parallel version will be faster, the right approach may be to start with a simple sequential version and build from there using profiling (mistake #98, \u201cNot using Go diagnostics tooling\u201d) and benchmarks (mistake #89, \u201cWriting inaccurate benchmarks\u201d), for example. It can be the only way to ensure that a concurrent implementation is worth it.
"},{"location":"89-benchmarks/","title":"Writing inaccurate benchmarks","text":"In general, we should never guess about performance. When writing optimizations, so many factors may come into play that even if we have a strong opinion about the results, it\u2019s rarely a bad idea to test them. However, writing benchmarks isn\u2019t straightforward. It can be pretty simple to write inaccurate benchmarks and make wrong assumptions based on them. The goal of this post is to examine four common and concrete traps leading to inaccuracy:
Before discussing these traps, let\u2019s briefly review how benchmarks work in Go. The skeleton of a benchmark is as follows:
func BenchmarkFoo(b *testing.B) {\n for i := 0; i < b.N; i++ {\n foo()\n }\n}\n
The function name starts with the Benchmark
prefix. The function under test (foo) is called within the for
loop. b.N
represents a variable number of iterations. When running a benchmark, Go tries to make it match the requested benchmark time. The benchmark time is set by default to 1 second and can be changed with the -benchtime
flag. b.N
starts at 1; if the benchmark completes in under 1 second, b.N
is increased, and the benchmark runs again until b.N
roughly matches benchtime:
$ go test -bench=.\ncpu: Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz\nBenchmarkFoo-4 73 16511228 ns/op\n
Here, the benchmark took about 1 second, and foo
was executed 73 times, for an average execution time of 16,511,228 nanoseconds. We can change the benchmark time using -benchtime
:
$ go test -bench=. -benchtime=2s\nBenchmarkFoo-4 150 15832169 ns/op\n
foo
was executed roughly twice more than during the previous benchmark.
Next, let\u2019s look at some common traps.
"},{"location":"89-benchmarks/#not-resetting-or-pausing-the-timer","title":"Not resetting or pausing the timer","text":"In some cases, we need to perform operations before the benchmark loop. These operations may take quite a while (for example, generating a large slice of data) and may significantly impact the benchmark results:
func BenchmarkFoo(b *testing.B) {\n expensiveSetup()\n for i := 0; i < b.N; i++ {\n functionUnderTest()\n }\n}\n
In this case, we can use the ResetTimer
method before entering the loop:
func BenchmarkFoo(b *testing.B) {\n expensiveSetup()\n b.ResetTimer() // Reset the benchmark timer\n for i := 0; i < b.N; i++ {\n functionUnderTest()\n }\n}\n
Calling ResetTimer
zeroes the elapsed benchmark time and memory allocation counters since the beginning of the test. This way, an expensive setup can be discarded from the test results.
What if we have to perform an expensive setup not just once but within each loop iteration?
func BenchmarkFoo(b *testing.B) {\n for i := 0; i < b.N; i++ {\n expensiveSetup()\n functionUnderTest()\n }\n}\n
We can\u2019t reset the timer, because that would be executed during each loop iteration. But we can stop and resume the benchmark timer, surrounding the call to expensiveSetup
:
func BenchmarkFoo(b *testing.B) {\n for i := 0; i < b.N; i++ {\n b.StopTimer() // Pause the benchmark timer\n expensiveSetup()\n b.StartTimer() // Resume the benchmark timer\n functionUnderTest()\n }\n}\n
Here, we pause the benchmark timer to perform the expensive setup and then resume the timer.
NoteThere\u2019s one catch to remember about this approach: if the function under test is too fast to execute compared to the setup function, the benchmark may take too long to complete. The reason is that it would take much longer than 1 second to reach benchtime
. Calculating the benchmark time is based solely on the execution time of functionUnderTest
. So, if we wait a significant time in each loop iteration, the benchmark will be much slower than 1 second. If we want to keep the benchmark, one possible mitigation is to decrease benchtime
.
We must be sure to use the timer methods to preserve the accuracy of a benchmark.
"},{"location":"89-benchmarks/#making-wrong-assumptions-about-micro-benchmarks","title":"Making wrong assumptions about micro-benchmarks","text":"A micro-benchmark measures a tiny computation unit, and it can be extremely easy to make wrong assumptions about it. Let\u2019s say, for example, that we aren\u2019t sure whether to use atomic.StoreInt32
or atomic.StoreInt64
(assuming that the values we handle will always fit in 32 bits). We want to write a benchmark to compare both functions:
func BenchmarkAtomicStoreInt32(b *testing.B) {\n var v int32\n for i := 0; i < b.N; i++ {\n atomic.StoreInt32(&v, 1)\n }\n}\n\nfunc BenchmarkAtomicStoreInt64(b *testing.B) {\n var v int64\n for i := 0; i < b.N; i++ {\n atomic.StoreInt64(&v, 1)\n }\n}\n
If we run this benchmark, here\u2019s some example output:
cpu: Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz\nBenchmarkAtomicStoreInt32\nBenchmarkAtomicStoreInt32-4 197107742 5.682 ns/op\nBenchmarkAtomicStoreInt64\nBenchmarkAtomicStoreInt64-4 213917528 5.134 ns/op\n
We could easily take this benchmark for granted and decide to use atomic.StoreInt64
because it appears to be faster. Now, for the sake of doing a fair benchmark, we reverse the order and test atomic.StoreInt64
first, followed by atomic.StoreInt32
. Here is some example output:
BenchmarkAtomicStoreInt64\nBenchmarkAtomicStoreInt64-4 224900722 5.434 ns/op\nBenchmarkAtomicStoreInt32\nBenchmarkAtomicStoreInt32-4 230253900 5.159 ns/op\n
This time, atomic.StoreInt32
has better results. What happened?
In the case of micro-benchmarks, many factors can impact the results, such as machine activity while running the benchmarks, power management, thermal scaling, and better cache alignment of a sequence of instructions. We must remember that many factors, even outside the scope of our Go project, can impact the results.
NoteWe should make sure the machine executing the benchmark is idle. However, external processes may run in the background, which may affect benchmark results. For that reason, tools such as perflock
can limit how much CPU a benchmark can consume. For example, we can run a benchmark with 70% of the total available CPU, giving 30% to the OS and other processes and reducing the impact of the machine activity factor on the results.
One option is to increase the benchmark time using the -benchtime
option. Similar to the law of large numbers in probability theory, if we run a benchmark a large number of times, it should tend to approach its expected value (assuming we omit the benefits of instructions caching and similar mechanics).
Another option is to use external tools on top of the classic benchmark tooling. For instance, the benchstat
tool, which is part of the golang.org/x
repository, allows us to compute and compare statistics about benchmark executions.
Let\u2019s run the benchmark 10 times using the -count
option and pipe the output to a specific file:
$ go test -bench=. -count=10 | tee stats.txt\ncpu: Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz\nBenchmarkAtomicStoreInt32-4 234935682 5.124 ns/op\nBenchmarkAtomicStoreInt32-4 235307204 5.112 ns/op\n// ...\nBenchmarkAtomicStoreInt64-4 235548591 5.107 ns/op\nBenchmarkAtomicStoreInt64-4 235210292 5.090 ns/op\n// ...\n
We can then run benchstat
on this file:
$ benchstat stats.txt\nname time/op\nAtomicStoreInt32-4 5.10ns \u00b1 1%\nAtomicStoreInt64-4 5.10ns \u00b1 1%\n
The results are the same: both functions take on average 5.10 nanoseconds to complete. We also see the percent variation between the executions of a given benchmark: \u00b1 1%. This metric tells us that both benchmarks are stable, giving us more confidence in the computed average results. Therefore, instead of concluding that atomic.StoreInt32
is faster or slower, we can conclude that its execution time is similar to that of atomic.StoreInt64
for the usage we tested (in a specific Go version on a particular machine).
In general, we should be cautious about micro-benchmarks. Many factors can significantly impact the results and potentially lead to wrong assumptions. Increasing the benchmark time or repeating the benchmark executions and computing stats with tools such as benchstat
can be an efficient way to limit external factors and get more accurate results, leading to better conclusions.
Let\u2019s also highlight that we should be careful about using the results of a micro-benchmark executed on a given machine if another system ends up running the application. The production system may act quite differently from the one on which we ran the micro-benchmark.
"},{"location":"89-benchmarks/#not-being-careful-about-compiler-optimizations","title":"Not being careful about compiler optimizations","text":"Another common mistake related to writing benchmarks is being fooled by compiler optimizations, which can also lead to wrong benchmark assumptions. In this section, we look at Go issue 14813 (https://github.com/golang/go/issues/14813, also discussed by Go project member Dave Cheney) with a population count function (a function that counts the number of bits set to 1):
const m1 = 0x5555555555555555\nconst m2 = 0x3333333333333333\nconst m4 = 0x0f0f0f0f0f0f0f0f\nconst h01 = 0x0101010101010101\n\nfunc popcnt(x uint64) uint64 {\n x -= (x >> 1) & m1\n x = (x & m2) + ((x >> 2) & m2)\n x = (x + (x >> 4)) & m4\n return (x * h01) >> 56\n}\n
This function takes and returns a uint64
. To benchmark this function, we can write the following:
func BenchmarkPopcnt1(b *testing.B) {\n for i := 0; i < b.N; i++ {\n popcnt(uint64(i))\n }\n}\n
However, if we execute this benchmark, we get a surprisingly low result:
cpu: Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz\nBenchmarkPopcnt1-4 1000000000 0.2858 ns/op\n
A duration of 0.28 nanoseconds is roughly one clock cycle, so this number is unreasonably low. The problem is that the developer wasn\u2019t careful enough about compiler optimizations. In this case, the function under test is simple enough to be a candidate for inlining: an optimization that replaces a function call with the body of the called function and lets us prevent a function call, which has a small footprint. Once the function is inlined, the compiler notices that the call has no side effects and replaces it with the following benchmark:
func BenchmarkPopcnt1(b *testing.B) {\n for i := 0; i < b.N; i++ {\n // Empty\n }\n}\n
The benchmark is now empty \u2014 which is why we got a result close to one clock cycle. To prevent this from happening, a best practice is to follow this pattern:
In our case, we write the following benchmark:
var global uint64 // Define a global variable\n\nfunc BenchmarkPopcnt2(b *testing.B) {\n var v uint64 // Define a local variable\n for i := 0; i < b.N; i++ {\n v = popcnt(uint64(i)) // Assign the result to the local variable\n }\n global = v // Assign the result to the global variable\n}\n
global
is a global variable, whereas v is a local variable whose scope is the benchmark function. During each loop iteration, we assign the result of popcnt
to the local variable. Then we assign the latest result to the global variable.
Why not assign the result of the popcnt call directly to global to simplify the test? Writing to a global variable is slower than writing to a local variable (these concepts are discussed in 100 Go Mistakes, mistake #95: \u201cNot understanding stack vs. heap\u201d). Therefore, we should write each result to a local variable to limit the footprint during each loop iteration.
If we run these two benchmarks, we now get a significant difference in the results:
cpu: Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz\nBenchmarkPopcnt1-4 1000000000 0.2858 ns/op\nBenchmarkPopcnt2-4 606402058 1.993 ns/op\n
BenchmarkPopcnt2
is the accurate version of the benchmark. It guarantees that we avoid the inlining optimizations, which can artificially lower the execution time or even remove the call to the function under test. Relying on the results of BenchmarkPopcnt1
could have led to wrong assumptions.
Let\u2019s remember the pattern to avoid compiler optimizations fooling benchmark results: assign the result of the function under test to a local variable, and then assign the latest result to a global variable. This best practice also prevents us from making incorrect assumptions.
"},{"location":"89-benchmarks/#being-fooled-by-the-observer-effect","title":"Being fooled by the observer effect","text":"In physics, the observer effect is the disturbance of an observed system by the act of observation. This effect can also be seen in benchmarks and can lead to wrong assumptions about results. Let\u2019s look at a concrete example and then try to mitigate it.
We want to implement a function receiving a matrix of int64
elements. This matrix has a fixed number of 512 columns, and we want to compute the total sum of the first eight columns, as shown in figure 1.
Figure 1: Computing the sum of the first eight columns.
For the sake of optimizations, we also want to determine whether varying the number of columns has an impact, so we also implement a second function with 513 columns. The implementation is the following:
func calculateSum512(s [][512]int64) int64 {\n var sum int64\n for i := 0; i < len(s); i++ { // Iterate over each row\n for j := 0; j < 8; j++ { // Iterate over the first eight columns\n sum += s[i][j] // Increment sum\n }\n }\n return sum\n}\n\nfunc calculateSum513(s [][513]int64) int64 {\n // Same implementation as calculateSum512\n}\n
We iterate over each row and then over the first eight columns, and we increment a sum variable that we return. The implementation in calculateSum513
remains the same.
We want to benchmark these functions to decide which one is the most performant given a fixed number of rows:
const rows = 1000\n\nvar res int64\n\nfunc BenchmarkCalculateSum512(b *testing.B) {\n var sum int64\n s := createMatrix512(rows) // Create a matrix of 512 columns\n b.ResetTimer()\n for i := 0; i < b.N; i++ {\n sum = calculateSum512(s) // Create a matrix of 512 columns\n }\n res = sum\n}\n\nfunc BenchmarkCalculateSum513(b *testing.B) {\n var sum int64\n s := createMatrix513(rows) // Create a matrix of 513 columns\n b.ResetTimer()\n for i := 0; i < b.N; i++ {\n sum = calculateSum513(s) // Calculate the sum\n }\n res = sum\n}\n
We want to create the matrix only once, to limit the footprint on the results. Therefore, we call createMatrix512
and createMatrix513
outside of the loop. We may expect the results to be similar as again we only want to iterate on the first eight columns, but this isn\u2019t the case (on my machine):
cpu: Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz\nBenchmarkCalculateSum512-4 81854 15073 ns/op\nBenchmarkCalculateSum513-4 161479 7358 ns/op\n
The second benchmark with 513 columns is about 50% faster. Again, because we iterate only over the first eight columns, this result is quite surprising.
To understand this difference, we need to understand the basics of CPU caches. In a nutshell, a CPU is composed of different caches (usually L1, L2, and L3). These caches reduce the average cost of accessing data from the main memory. In some conditions, the CPU can fetch data from the main memory and copy it to L1. In this case, the CPU tries to fetch into L1 the matrix\u2019s subset that calculateSum
is interested in (the first eight columns of each row). However, the matrix fits in memory in one case (513 columns) but not in the other case (512 columns).
This isn\u2019t in the scope of this post to explain why, but we look at this problem in 100 Go Mistakes, mistake #91: \u201cNot understanding CPU caches.\u201d
Coming back to the benchmark, the main issue is that we keep reusing the same matrix in both cases. Because the function is repeated thousands of times, we don\u2019t measure the function\u2019s execution when it receives a plain new matrix. Instead, we measure a function that gets a matrix that already has a subset of the cells present in the cache. Therefore, because calculateSum513
leads to fewer cache misses, it has a better execution time.
This is an example of the observer effect. Because we keep observing a repeatedly called CPU-bound function, CPU caching may come into play and significantly affect the results. In this example, to prevent this effect, we should create a matrix during each test instead of reusing one:
func BenchmarkCalculateSum512(b *testing.B) {\n var sum int64\n for i := 0; i < b.N; i++ {\n b.StopTimer()\n s := createMatrix512(rows) // Create a new matrix during each loop iteration\n b.StartTimer()\n sum = calculateSum512(s)\n }\n res = sum\n}\n
A new matrix is now created during each loop iteration. If we run the benchmark again (and adjust benchtime
\u2014 otherwise, it takes too long to execute), the results are closer to each other:
cpu: Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz\nBenchmarkCalculateSum512-4 1116 33547 ns/op\nBenchmarkCalculateSum513-4 998 35507 ns/op\n
Instead of making the incorrect assumption that calculateSum513 is faster, we see that both benchmarks lead to similar results when receiving a new matrix.
As we have seen in this post, because we were reusing the same matrix, CPU caches significantly impacted the results. To prevent this, we had to create a new matrix during each loop iteration. In general, we should remember that observing a function under test may lead to significant differences in results, especially in the context of micro-benchmarks of CPU-bound functions where low-level optimizations matter. Forcing a benchmark to re-create data during each iteration can be a good way to prevent this effect.
"},{"location":"9-generics/","title":"Being confused about when to use generics","text":"Generics is a fresh addition to the language. In a nutshell, it allows writing code with types that can be specified later and instantiated when needed. However, it can be pretty easy to be confused about when to use generics and when not to. Throughout this post, we will describe the concept of generics in Go and then delve into common use and misuses.
"},{"location":"9-generics/#concepts","title":"Concepts","text":"Consider the following function that extracts all the keys from a map[string]int
type:
func getKeys(m map[string]int) []string {\n var keys []string\n for k := range m {\n keys = append(keys, k)\n }\n return keys\n}\n
What if we would like to use a similar feature for another map type such as a map[int]string
? Before generics, Go developers had a couple of options: using code generation, reflection, or duplicating code.
For example, we could write two functions, one for each map type, or even try to extend getKeys
to accept different map types:
func getKeys(m any) ([]any, error) {\n switch t := m.(type) {\n default:\n return nil, fmt.Errorf(\"unknown type: %T\", t)\n case map[string]int:\n var keys []any\n for k := range t {\n keys = append(keys, k)\n }\n return keys, nil\n case map[int]string:\n // Copy the extraction logic\n }\n}\n
We can start noticing a couple of issues:
range
loop.int
or string
, we are obliged to return a slice of empty interfaces to factor out key types. This approach increases the effort on the caller-side as the client may also have to perform a type check of the keys or extra conversion.Thanks to generics, we can now refactor this code using type parameters.
Type parameters are generic types we can use with functions and types. For example, the following function accepts a type parameter:
func foo[T any](t T) {\n // ...\n}\n
When calling foo
, we will pass a type argument of any type. Passing a type argument is called instantiation because the work is done at compile time which keeps type safety as part of the core language features and avoids runtime overheads.
Let\u2019s get back to the getKeys
function and use type parameters to write a generic version that would accept any kind of map:
func getKeys[K comparable, V any](m map[K]V) []K {\n var keys []K <2>\n for k := range m {\n keys = append(keys, k)\n }\n return keys\n}\n
To handle the map, we defined two kinds of type parameters. First, the values can be of any type: V any
. However, in Go, the map keys can\u2019t be of any type. For example, we cannot use slices:
var m map[[]byte]int\n
This code leads to a compilation error: invalid map key type []byte
. Therefore, instead of accepting any key type, we are obliged to restrict type arguments so that the key type meets specific requirements. Here, being comparable (we can use ==
or !=
). Hence, we defined K
as comparable
instead of any
.
Restricting type arguments to match specific requirements is called a constraint. A constraint is an interface type that can contain:
Let\u2019s see a concrete example for the latter. Imagine we don\u2019t want to accept any comparable
type for map key type. For instance, we would like to restrict it to either int
or string
types. We can define a custom constraint this way:
type customConstraint interface {\n ~int | ~string // Define a custom type that will restrict types to int and string\n}\n\n// Change the type parameter K to be custom\nfunc getKeys[K customConstraint, V any](m map[K]V) []K {\n // Same implementation\n}\n
First, we define a customConstraint
interface to restrict the types to be either int
or string
using the union operator |
(we will discuss the use of ~
a bit later). Then, K
is now a customConstraint
instead of a comparable
as before.
Now, the signature of getKeys
enforces that we can call it with a map of any value type, but the key type has to be an int
or a string
. For example, on the caller-side:
m = map[string]int{\n \"one\": 1,\n \"two\": 2,\n \"three\": 3,\n}\nkeys := getKeys(m)\n
Note that Go can infer that getKeys
is called with a string
type argument. The previous call was similar to this:
keys := getKeys[string](m)\n
Note What\u2019s the difference between a constraint using ~int
or int
? Using int
restricts it to that type, whereas ~int
restricts all the types whose underlying type is an int
.
To illustrate it, let\u2019s imagine a constraint where we would like to restrict a type to any int
type implementing the String() string
method:
type customConstraint interface {\n ~int\n String() string\n}\n
Using this constraint will restrict type arguments to custom types like this one:
type customInt int\n\nfunc (i customInt) String() string {\n return strconv.Itoa(int(i))\n}\n
As customInt
is an int
and implements the String() string
method, the customInt
type satisfies the constraint defined.
However, if we change the constraint to contain an int
instead of an ~int
, using customInt
would lead to a compilation error because the int
type doesn\u2019t implement String() string
.
Let\u2019s also note the constraints
package contains a set of common constraints such as Signed
that includes all the signed integer types. Let\u2019s ensure that a constraint doesn\u2019t already exist in this package before creating a new one.
So far, we have discussed examples using generics for functions. However, we can also use generics with data structures.
For example, we will create a linked list containing values of any type. Meanwhile, we will write an Add
method to append a node:
type Node[T any] struct { // Use type parameter\n Val T\n next *Node[T]\n}\n\nfunc (n *Node[T]) Add(next *Node[T]) { // Instantiate type receiver\n n.next = next\n}\n
We use type parameters to define T
and use both fields in Node
. Regarding the method, the receiver is instantiated. Indeed, because Node
is generic, it has to follow also the type parameter defined.
One last thing to note about type parameters: they can\u2019t be used on methods, only on functions. For example, the following method wouldn\u2019t compile:
type Foo struct {}\n\nfunc (Foo) bar[T any](t T) {}\n
./main.go:29:15: methods cannot have type parameters\n
Now, let\u2019s delve into concrete cases where we should and shouldn\u2019t use generics.
"},{"location":"9-generics/#common-uses-and-misuses","title":"Common uses and misuses","text":"So when are generics useful? Let\u2019s discuss a couple of common uses where generics are recommended:
func merge[T any](ch1, ch2 <-chan T) <-chan T {\n // ...\n}\n
sort
package contains functions to sort different slice types such as sort.Ints
or sort.Float64s
. Using type parameters, we can factor out the sorting behaviors that rely on three methods, Len
, Less
, and Swap
:type sliceFn[T any] struct { // Use type parameter\n s []T\n compare func(T, T) bool // Compare two T elements\n}\n\nfunc (s sliceFn[T]) Len() int { return len(s.s) }\nfunc (s sliceFn[T]) Less(i, j int) bool { return s.compare(s.s[i], s.s[j]) }\nfunc (s sliceFn[T]) Swap(i, j int) { s.s[i], s.s[j] = s.s[j], s.s[i] }\n
Conversely, when is it recommended not to use generics?
io.Writer
and call the Write
method:func foo[T io.Writer](w T) {\n b := getBytes()\n _, _ = w.Write(b)\n}\n
Though generics can be very helpful in particular conditions, we should be cautious about when to use them and not use them.
In general, when we want to answer when not to use generics, we can find similarities with when not to use interfaces. Indeed, generics introduce a form of abstraction, and we have to remember that unnecessary abstractions introduce complexity.
Let\u2019s not pollute our code with needless abstractions, and let\u2019s focus on solving concrete problems for now. It means that we shouldn\u2019t use type parameters prematurely. Let\u2019s wait until we are about to write boilerplate code to consider using generics.
"},{"location":"92-false-sharing/","title":"Writing concurrent code that leads to false sharing","text":"In previous sections, we have discussed the fundamental concepts of CPU caching. We have seen that some specific caches (typically, L1 and L2) aren\u2019t shared among all the logical cores but are specific to a physical core. This specificity has some concrete impacts such as concurrency and the concept of false sharing, which can lead to a significant performance decrease. Let\u2019s look at what false sharing is via an example and then see how to prevent it.
In this example, we use two structs, Input
and Result
:
type Input struct {\n a int64\n b int64\n}\n\ntype Result struct {\n sumA int64\n sumB int64\n}\n
The goal is to implement a count
function that receives a slice of Input
and computes the following:
Input.a
fields into Result.sumA
Input.b
fields into Result.sumB
For the sake of the example, we implement a concurrent solution with one goroutine that computes sumA
and another that computes sumB
:
func count(inputs []Input) Result {\n wg := sync.WaitGroup{}\n wg.Add(2)\n\n result := Result{} // Init the result struct\n\n go func() {\n for i := 0; i < len(inputs); i++ {\n result.sumA += inputs[i].a // Computes sumA\n }\n wg.Done()\n }()\n\n go func() {\n for i := 0; i < len(inputs); i++ {\n result.sumB += inputs[i].b // Computes sumB\n }\n wg.Done()\n }()\n\n wg.Wait()\n return result\n}\n
We spin up two goroutines: one that iterates over each a field and another that iterates over each b field. This example is fine from a concurrency perspective. For instance, it doesn\u2019t lead to a data race, because each goroutine increments its own variable. But this example illustrates the false sharing concept that degrades expected performance.
Let\u2019s look at the main memory. Because sumA
and sumB
are allocated contiguously, in most cases (seven out of eight), both variables are allocated to the same memory block:
In this example, sumA and sumB are part of the same memory block.
Now, let\u2019s assume that the machine contains two cores. In most cases, we should eventually have two threads scheduled on different cores. So if the CPU decides to copy this memory block to a cache line, it is copied twice:
Each block is copied to a cache line on both code 0 and core 1.
Both cache lines are replicated because L1D (L1 data) is per core. Recall that in our example, each goroutine updates its own variable: sumA
on one side, and sumB
on the other side:
Each goroutine updates its own variable.
Because these cache lines are replicated, one of the goals of the CPU is to guarantee cache coherency. For example, if one goroutine updates sumA
and another reads sumA
(after some synchronization), we expect our application to get the latest value.
However, our example doesn\u2019t do exactly this. Both goroutines access their own variables, not a shared one. We might expect the CPU to know about this and understand that it isn\u2019t a conflict, but this isn\u2019t the case. When we write a variable that\u2019s in a cache, the granularity tracked by the CPU isn\u2019t the variable: it\u2019s the cache line.
When a cache line is shared across multiple cores and at least one goroutine is a writer, the entire cache line is invalidated. This happens even if the updates are logically independent (for example, sumA
and sumB
). This is the problem of false sharing, and it degrades performance.
Internally, a CPU uses the MESI protocol to guarantee cache coherency. It tracks each cache line, marking it modified, exclusive, shared, or invalid (MESI).
One of the most important aspects to understand about memory and caching is that sharing memory across cores isn\u2019t real\u2014it\u2019s an illusion. This understanding comes from the fact that we don\u2019t consider a machine a black box; instead, we try to have mechanical sympathy with underlying levels.
So how do we solve false sharing? There are two main solutions.
The first solution is to use the same approach we\u2019ve shown but ensure that sumA
and sumB
aren\u2019t part of the same cache line. For example, we can update the Result
struct to add padding between the fields. Padding is a technique to allocate extra memory. Because an int64
requires an 8-byte allocation and a cache line 64 bytes long, we need 64 \u2013 8 = 56 bytes of padding:
type Result struct {\n sumA int64\n _ [56]byte // Padding\n sumB int64\n}\n
The next figure shows a possible memory allocation. Using padding, sumA
and sumB
will always be part of different memory blocks and hence different cache lines.
sumA and sumB are part of different memory blocks.
If we benchmark both solutions (with and without padding), we see that the padding solution is significantly faster (about 40% on my machine). This is an important improvement that results from the addition of padding between the two fields to prevent false sharing.
The second solution is to rework the structure of the algorithm. For example, instead of having both goroutines share the same struct, we can make them communicate their local result via channels. The result benchmark is roughly the same as with padding.
In summary, we must remember that sharing memory across goroutines is an illusion at the lowest memory levels. False sharing occurs when a cache line is shared across two cores when at least one goroutine is a writer. If we need to optimize an application that relies on concurrency, we should check whether false sharing applies, because this pattern is known to degrade application performance. We can prevent false sharing with either padding or communication.
"},{"location":"98-profiling-execution-tracing/","title":"Not using Go diagnostics tooling","text":"Go offers a few excellent diagnostics tools to help us get insights into how an application performs. This post focuses on the most important ones: profiling and the execution tracer. Both tools are so important that they should be part of the core toolset of any Go developer who is interested in optimization. First, let\u2019s discuss profiling.
"},{"location":"98-profiling-execution-tracing/#profiling","title":"Profiling","text":"Profiling provides insights into the execution of an application. It allows us to resolve performance issues, detect contention, locate memory leaks, and more. These insights can be collected via several profiles:
CPU
\u2014 Determines where an application spends its timeGoroutine
\u2014 Reports the stack traces of the ongoing goroutinesHeap
\u2014 Reports heap memory allocation to monitor current memory usage and check for possible memory leaksMutex
\u2014 Reports lock contentions to see the behaviors of the mutexes used in our code and whether an application spends too much time in locking callsBlock
\u2014 Shows where goroutines block waiting on synchronization primitivesProfiling is achieved via instrumentation using a tool called a profiler, in Go: pprof
. First, let\u2019s understand how and when to enable pprof
; then, we discuss the most critical profile types.
There are several ways to enable pprof
. For example, we can use the net/http/pprof
package to serve the profiling data via HTTP:
package main\n\nimport (\n \"fmt\"\n \"log\"\n \"net/http\"\n _ \"net/http/pprof\" // Blank import to pprof\n)\n\nfunc main() {\n // Exposes an HTTP endpoint\n http.HandleFunc(\"/\", func(w http.ResponseWriter, r *http.Request) {\n fmt.Fprintf(w, \"\")\n })\n log.Fatal(http.ListenAndServe(\":80\", nil))\n}\n
Importing net/http/pprof
leads to a side effect that allows us to reach the pprof URL: http://host/debug/pprof. Note that enabling pprof
is safe even in production (https://go.dev/doc/diagnostics#profiling). The profiles that impact performance, such as CPU profiling, aren\u2019t enabled by default, nor do they run continuously: they are activated only for a specific period.
Now that we have seen how to expose a pprof
endpoint, let\u2019s discuss the most common profiles.
The CPU profiler relies on the OS and signaling. When it is activated, the application asks the OS to interrupt it every 10 ms by default via a SIGPROF
signal. When the application receives a SIGPROF
, it suspends the current activity and transfers the execution to the profiler. The profiler collects data such as the current goroutine activity and aggregates execution statistics that we can retrieve. Then it stops, and the execution resumes until the next SIGPROF
.
We can access the /debug/pprof/profile endpoint to activate CPU profiling. Accessing this endpoint executes CPU profiling for 30 seconds by default. For 30 seconds, our application is interrupted every 10 ms. Note that we can change these two default values: we can use the seconds
parameter to pass to the endpoint how long the profiling should last (for example, /debug/pprof/profile?seconds=15), and we can change the interruption rate (even to less than 10 ms). But in most cases, 10 ms should be enough, and in decreasing this value (meaning increasing the rate), we should be careful not to harm performance. After 30 seconds, we download the results of the CPU profiler.
We can also enable the CPU profiler using the -cpuprofile
flag, such as when running a benchmark. For example, the following command produces the same type of file that can be downloaded via /debug/ pprof/profile.
$ go test -bench=. -cpuprofile profile.out\n
From this file, we can navigate to the results using go tool
:
$ go tool pprof -http=:8080 <file>\n
This command opens a web UI showing the call graph. The next figure shows an example taken from an application. The larger the arrow, the more it was a hot path. We can then navigate into this graph and get execution insights.
Figure 1: The call graph of an application during 30 seconds.
For example, the graph in the next figure tells us that during 30 seconds, 0.06 seconds were spent in the decode
method (*FetchResponse
receiver). Of these 0.06 seconds, 0.02 were spent in RecordBatch.decode
and 0.01 in makemap
(creating a map).
Figure 2: Example call graph.
We can also access this kind of information from the web UI with different representations. For example, the Top view sorts the functions per execution time, and Flame Graph visualizes the execution time hierarchy. The UI can even display the expensive parts of the source code line by line.
NoteWe can also delve into profiling data via a command line. However, we focus on the web UI in this post.
Thanks to this data, we can get a general idea of how an application behaves:
runtime.mallogc
can mean an excessive number of small heap allocations that we can try to minimize.syscall.Read
or syscall.Write
means the application spends a significant amount of time in Kernel mode. Working on I/O buffering may be an avenue for improvement.These are the kinds of insights we can get from the CPU profiler. It\u2019s valuable to understand the hottest code path and identify bottlenecks. But it won\u2019t determine more than the configured rate because the CPU profiler is executed at a fixed pace (by default, 10 ms). To get finer-grained insights, we should use tracing, which we discuss later in this post.
NoteWe can also attach labels to the different functions. For example, imagine a common function called from different clients. To track the time spent for both clients, we can use pprof.Labels
.
Heap profiling allows us to get statistics about the current heap usage. Like CPU profiling, heap profiling is sample-based. We can change this rate, but we shouldn\u2019t be too granular because the more we decrease the rate, the more effort heap profiling will require to collect data. By default, samples are profiled at one allocation for every 512 KB of heap allocation.
If we reach /debug/pprof/heap/, we get raw data that can be hard to read. However, we can download a heap profile using /debug/pprof/heap/?debug=0 and then open it with go tool
(the same command as in the previous section) to navigate into the data using the web UI.
The next figure shows an example of a heap graph. Calling the MetadataResponse.decode
method leads to allocating 1536 KB of heap data (which represents 6.32% of the total heap). However, 0 out of these 1536 KB were allocated by this function directly, so we need to inspect the second call. The TopicMetadata.decode
method allocated 512 KB out of the 1536 KB; the rest \u2014 1024 KB \u2014 were allocated in another method.
Figure 3: A heap graph.
This is how we can navigate the call chain to understand what part of an application is responsible for most of the heap allocations. We can also look at different sample types:
alloc_objects
\u2014 Total number of objects allocatedalloc_space
\u2014 Total amount of memory allocatedinuse_object
s \u2014 Number of objects allocated and not yet releasedinuse_space
\u2014 Amount of memory allocated and not yet releasedAnother very helpful capability with heap profiling is tracking memory leaks. With a GC-based language, the usual procedure is the following:
Forcing a GC before downloading data is a way to prevent false assumptions. For example, if we see a peak of retained objects without running a GC first, we cannot be sure whether it\u2019s a leak or objects that the next GC will collect.
Using pprof
, we can download a heap profile and force a GC in the meantime. The procedure in Go is the following:
$ go tool pprof -http=:8080 -diff_base <file2> <file1>\n
The next figure shows the kind of data we can access. For example, the amount of heap memory held by the newTopicProducer method (top left) has decreased (\u2013513 KB). In contrast, the amount held by updateMetadata (bottom right) has increased (+512 KB). Slow increases are normal. The second heap profile may have been calculated in the middle of a service call, for example. We can repeat this process or wait longer; the important part is to track steady increases in allocations of a specific object.
Figure 4: The differences between the two heap profiles. Note
Another type of profiling related to the heap is allocs
, which reports allocations. Heap profiling shows the current state of the heap memory. To get insights about past memory allocations since the application started, we can use allocations profiling. As discussed, because stack allocations are cheap, they aren\u2019t part of this profiling, which only focuses on the heap.
The goroutine
profile reports the stack trace of all the current goroutines in an application. We can download a file using /debug/pprof/goroutine/?debug=0 and use go tool again. The next figure shows the kind of information we can get.
Figure 5: Goroutine graph.
We can see the current state of the application and how many goroutines were created per function. In this case, withRecover
has created 296 ongoing goroutines (63%), and 29 were related to a call to responseFeeder
.
This kind of information is also beneficial if we suspect goroutine leaks. We can look at goroutine profiler data to know which part of a system is the suspect.
"},{"location":"98-profiling-execution-tracing/#block-profiling","title":"Block Profiling","text":"The block
profile reports where ongoing goroutines block waiting on synchronization primitives. Possibilities include
Block profiling also records the amount of time a goroutine has been waiting and is accessible via /debug/pprof/block. This profile can be extremely helpful if we suspect that performance is being harmed by blocking calls.
The block
profile isn\u2019t enabled by default: we have to call runtime.SetBlockProfileRate
to enable it. This function controls the fraction of goroutine blocking events that are reported. Once enabled, the profiler will keep collecting data in the background even if we don\u2019t call the /debug/pprof/block endpoint. Let\u2019s be cautious if we want to set a high rate so we don\u2019t harm performance.
If we face a deadlock or suspect that goroutines are in a blocked state, the full goroutine stack dump (/debug/pprof/goroutine/?debug=2) creates a dump of all the current goroutine stack traces. This can be helpful as a first analysis step. For example, the following dump shows a Sarama goroutine blocked for 1,420 minutes on a channel-receive operation:
goroutine 2494290 [chan receive, 1420 minutes]:\ngithub.com/Shopify/sarama.(*syncProducer).SendMessages(0xc00071a090,\n[CA]{0xc0009bb800, 0xfb, 0xfb})\n/app/vendor/github.com/Shopify/sarama/sync_producer.go:117 +0x149\n
"},{"location":"98-profiling-execution-tracing/#mutex-profiling","title":"Mutex Profiling","text":"The last profile type is related to blocking but only regarding mutexes. If we suspect that our application spends significant time waiting for locking mutexes, thus harming execution, we can use mutex profiling. It\u2019s accessible via /debug/pprof/mutex.
This profile works in a manner similar to that for blocking. It\u2019s disabled by default: we have to enable it using runtime.SetMutexProfileFraction
, which controls the fraction of mutex contention events reported.
Following are a few additional notes about profiling:
threadcreate
profile because it\u2019s been broken since 2013 (https://github.com/golang/go/issues/6104).pprof
is extensible, and we can create our own custom profiles using pprof.Profile
.We have seen the most important profiles that we can enable to help us understand how an application performs and possible avenues for optimization. In general, enabling pprof
is recommended, even in production, because in most cases it offers an excellent balance between its footprint and the amount of insight we can get from it. Some profiles, such as the CPU profile, lead to performance penalties but only during the time they are enabled.
Let\u2019s now look at the execution tracer.
"},{"location":"98-profiling-execution-tracing/#execution-tracer","title":"Execution Tracer","text":"The execution tracer is a tool that captures a wide range of runtime events with go tool
to make them available for visualization. It is helpful for the following:
Let\u2019s try it with an example given the Concurrency isn\u2019t Always Faster in Go section. We discussed two parallel versions of the merge sort algorithm. The issue with the first version was poor parallelization, leading to the creation of too many goroutines. Let\u2019s see how the tracer can help us in validating this statement.
We will write a benchmark for the first version and execute it with the -trace flag to enable the execution tracer:
$ go test -bench=. -v -trace=trace.out\n
Note We can also download a remote trace file using the /debug/pprof/ trace?debug=0 pprof endpoint.
This command creates a trace.out file that we can open using go tool:
$ go tool trace trace.out\n2021/11/26 21:36:03 Parsing trace...\n2021/11/26 21:36:31 Splitting trace...\n2021/11/26 21:37:00 Opening browser. Trace viewer is listening on\n http://127.0.0.1:54518\n
The web browser opens, and we can click View Trace to see all the traces during a specific timeframe, as shown in the next figure. This figure represents about 150 ms. We can see multiple helpful metrics, such as the goroutine count and the heap size. The heap size grows steadily until a GC is triggered. We can also observe the activity of the Go application per CPU core. The timeframe starts with user-level code; then a \u201cstop the world\u201d is executed, which occupies the four CPU cores for approximately 40 ms.
Figure 6: Showing goroutine activity and runtime events such as a GC phase.
Regarding concurrency, we can see that this version uses all the available CPU cores on the machine. However, the next figure zooms in on a portion of 1 ms. Each bar corresponds to a single goroutine execution. Having too many small bars doesn\u2019t look right: it means execution that is poorly parallelized.
Figure 7: Too many small bars mean poorly parallelized execution.
The next figure zooms even closer to see how these goroutines are orchestrated. Roughly 50% of the CPU time isn\u2019t spent executing application code. The white spaces represent the time the Go runtime takes to spin up and orchestrate new goroutines.
Figure 8: About 50% of CPU time is spent handling goroutine switches.
Let\u2019s compare this with the second parallel implementation, which was about an order of magnitude faster. The next figure again zooms to a 1 ms timeframe.
Figure 9: The number of white spaces has been significantly reduced, proving that the CPU is more fully occupied.
Each goroutine takes more time to execute, and the number of white spaces has been significantly reduced. Hence, the CPU is much more occupied executing application code than it was in the first version. Each millisecond of CPU time is spent more efficiently, explaining the benchmark differences.
Note that the granularity of the traces is per goroutine, not per function like CPU profiling. However, it\u2019s possible to define user-level tasks to get insights per function or group of functions using the runtime/trace
package.
For example, imagine a function that computes a Fibonacci number and then writes it to a global variable using atomic. We can define two different tasks:
var v int64\n// Creates a fibonacci task\nctx, fibTask := trace.NewTask(context.Background(), \"fibonacci\")\ntrace.WithRegion(ctx, \"main\", func() {\n v = fibonacci(10)\n})\nfibTask.End()\n\n// Creates a store task\nctx, fibStore := trace.NewTask(ctx, \"store\")\ntrace.WithRegion(ctx, \"main\", func() {\n atomic.StoreInt64(&result, v)\n})\nfibStore.End()\n
Using go tool
, we can get more precise information about how these two tasks perform. In the previous trace UI, we can see the boundaries for each task per goroutine. In User-Defined Tasks, we can follow the duration distribution:
Figure 10: Distribution of user-level tasks.
We see that in most cases, the fibonacci
task is executed in less than 15 microseconds, whereas the store
task takes less than 6309 nanoseconds.
In the previous section, we discussed the kinds of information we can get from CPU profiling. What are the main differences compared to the data we can get from user-level traces?
runtime/trace
package)In summary, the execution tracer is a powerful tool for understanding how an application performs. As we have seen with the merge sort example, we can identify poorly parallelized execution. However, the tracer\u2019s granularity remains per goroutine unless we manually use runtime/trace
compared to a CPU profile, for example. We can use both profiling and the execution tracer to get the most out of the standard Go diagnostics tools when optimizing an application.
If you're a Go developer looking to improve your skills, the 100 Go Mistakes and How to Avoid Them book is for you. With a focus on practical examples, this book covers a wide range of topics from concurrency and error handling to testing and code organization. You'll learn to write more idiomatic, efficient, and maintainable code and become a proficient Go developer.
Read a summary of the 100 mistakes or the first chapter.
"},{"location":"book/#quotes-and-ratings","title":"Quotes and Ratings","text":"Krystian (Goodreads user)
This is an exceptional book. Usually, if a book contains either high-quality explanations or is written succinctly, I consider myself lucky to have found it. This one combines these two characteristics, which is super rare. It's another Go book for me and I still had quite a lot of \"a-ha!\" moments while reading it, and all of that without the unnecessary fluff, just straight to the point.
Akash Chetty
The book is completely exceptional, especially the examples carved out for each topic are really great. There is one topic that I struggled to understand is Concurrency but the way it is explained in this book is truly an art of genius.
Neeraj Shah
This should be the required reading for all Golang developers before they touch code in Production... It's the Golang equivalent of the legendary 'Effective Java' by Joshua Bloch.
Anupam Sengupta
Not having this will be the 101st mistake a Go programmer could make.
Manning, Goodreads, and Amazon reviews: 4.7/5 avg rating"},{"location":"book/#where-to-buy","title":"Where to Buy?","text":"
100 Go Mistakes and How to Avoid Them (\ud83c\uddec\ud83c\udde7 edition: paper, digital, or audiobook)
au35har
)Go\u8a00\u8a9e100Tips \u958b\u767a\u8005\u306b\u3042\u308a\u304c\u3061\u306a\u9593\u9055\u3044\u3078\u306e\u5bfe\u51e6\u6cd5 (\ud83c\uddef\ud83c\uddf5 edition: paper or digital)
100\u4e2aGo\u8bed\u8a00\u5178\u578b\u9519\u8bef (\ud83c\udde8\ud83c\uddf3 edition: paper or digital)
Go 100\uac00\uc9c0 \uc2e4\uc218 \ud328\ud134\uacfc \uc194\ub8e8\uc158 (\ud83c\uddf0\ud83c\uddf7 edition: paper or digital)
Covers (English, Japanese, Chinese, and Korean)"},{"location":"book/#about-the-author","title":"About the Author","text":"
Teiva Harsanyi is a senior software engineer at Google. He has worked in various domains, including insurance, transportation, and safety-critical industries like air traffic management. He is passionate about Go and how to design and implement reliable systems.
"},{"location":"chapter-1/","title":"Go: Simple to learn but hard to master","text":"This chapter covers
Making mistakes is part of everyone\u2019s life. As Albert Einstein once said,
Albert Einstein
A person who never made a mistake never tried anything new.
What matters in the end isn\u2019t the number of mistakes we make, but our capacity to learn from them. This assertion also applies to programming. The seniority we acquire in a language isn\u2019t a magical process; it involves making many mistakes and learning from them. The purpose of this book is centered around this idea. It will help you, the reader, become a more proficient Go developer by looking at and learning from 100 common mistakes people make in many areas of the language.
This chapter presents a quick refresher as to why Go has become mainstream over the years. We\u2019ll discuss why, despite Go being considered simple to learn, mastering its nuances can be challenging. Finally, we\u2019ll introduce the concepts this book covers.
"},{"location":"chapter-1/#go-outline","title":"Go outline","text":"If you are reading this book, it\u2019s likely that you\u2019re already sold on Go. Therefore, this section provides a brief reminder about what makes Go such a powerful language.
Software engineering has evolved considerably during the past decades. Most modern systems are no longer written by a single person but by teams consisting of multiple programmers\u2014sometimes even hundreds, if not thousands. Nowadays, code must be readable, expressive, and maintainable to guarantee a system\u2019s durability over the years. Meanwhile, in our fast-moving world, maximizing agility and reducing the time to market is critical for most organizations. Programming should also follow this trend, and companies strive to ensure that software engineers are as productive as possible when reading, writing, and maintaining code.
In response to these challenges, Google created the Go programming language in 2007. Since then, many organizations have adopted the language to support various use cases: APIs, automation, databases, CLIs (command-line interfaces), and so on. Many today consider Go the language of the cloud.
Feature-wise, Go has no type inheritance, no exceptions, no macros, no partial functions, no support for lazy variable evaluation or immutability, no operator overloading, no pattern matching, and on and on. Why are these features missing from the language? The official Go FAQ gives us some insight:
Go FAQ
Why does Go not have feature X? Your favorite feature may be missing because it doesn\u2019t fit, because it affects compilation speed or clarity of design, or because it would make the fundamental system model too difficult.
Judging the quality of a programming language via its number of features is probably not an accurate metric. At least, it\u2019s not an objective of Go. Instead, Go utilizes a few essential characteristics when adopting a language at scale for an organization. These include the following:
Go was built from the ground up with solid features such as outstanding concurrency primitives with goroutines and channels. There\u2019s not a strong need to rely on external libraries to build efficient concurrent applications. Observing how important concurrency is these days also demonstrates why Go is such a suitable language for the present and probably for the foreseeable future.
Some also consider Go a simple language. And, in a sense, this isn\u2019t necessarily wrong. For example, a newcomer can learn the language\u2019s main features in less than a day. So why read a book centered on the concept of mistakes if Go is simple?
"},{"location":"chapter-1/#simple-doesnt-mean-easy","title":"Simple doesn\u2019t mean easy","text":"There is a subtle difference between simple and easy. Simple, applied to a technology, means not complicated to learn or understand. However, easy means that we can achieve anything without much effort. Go is simple to learn but not necessarily easy to master.
Let\u2019s take concurrency, for example. In 2019, a study focusing on concurrency bugs was published: Understanding Real-World Concurrency Bugs in Go. This study was the first systematic analysis of concurrency bugs. It focused on multiple popular Go repositories such as Docker, gRPC, and Kubernetes. One of the most important takeaways from this study is that most of the blocking bugs are caused by inaccurate use of the message-passing paradigm via channels, despite the belief that message passing is easier to handle and less error-prone than sharing memory.
What should be an appropriate reaction to such a takeaway? Should we consider that the language designers were wrong about message passing? Should we reconsider how we deal with concurrency in our project? Of course not.
It\u2019s not a question of confronting message passing versus sharing memory and determining the winner. However, it\u2019s up to us as Go developers to thoroughly understand how to use concurrency, its implications on modern processors, when to favor one approach over the other, and how to avoid common traps. This example highlights that although a concept such as channels and goroutines can be simple to learn, it isn\u2019t an easy topic in practice.
This leitmotif\u2014simple doesn\u2019t mean easy\u2014can be generalized to many aspects of Go, not only concurrency. Hence, to be proficient Go developers, we must have a thorough understanding of many aspects of the language, which requires time, effort, and mistakes.
This book aims to help accelerate our journey toward proficiency by delving into 100 Go mistakes.
"},{"location":"chapter-1/#100-go-mistakes","title":"100 Go mistakes","text":"Why should we read a book about common Go mistakes? Why not deepen our knowledge with an ordinary book that would dig into different topics?
In a 2011 article, neuroscientists proved that the best time for brain growth is when we\u2019re facing mistakes. 1 Haven\u2019t we all experienced the process of learning from a mistake and recalling that occasion after months or even years, when some context related to it? As presented in another article, by Janet Metcalfe, this happens because mistakes have a facilitative effect. 2 The main idea is that we can remember not only the error but also the context surrounding the mistake. This is one of the reasons why learning from mistakes is so efficient.
To strengthen this facilitative effect, this book accompanies each mistake as much as possible with real-world examples. This book isn\u2019t only about theory; it also helps us get better at avoiding mistakes and making more well-informed, conscious decisions because we now understand the rationale behind them.
Unknown
Tell me and I forget. Teach me and I remember. Involve me and I learn.
This book presents seven main categories of mistakes. Overall, the mistakes can be classified as
We introduce each mistake category next.
"},{"location":"chapter-1/#bugs","title":"Bugs","text":"The first type of mistake and probably the most obvious is software bugs. In 2020, a study conducted by Synopsys estimated the cost of software bugs in the U.S. alone to be over $2 trillion. 3
Furthermore, bugs can also lead to tragic impacts. We can, for example, mention cases such as Therac-25, a radiation therapy machine produced by Atomic Energy of Canada Limited (AECL). Because of a race condition, the machine gave its patients radiation doses that were hundreds of times greater than expected, leading to the death of three patients. Hence, software bugs aren\u2019t only about money. As developers, we should remember how impactful our jobs are.
This book covers plenty of cases that could lead to various software bugs, including data races, leaks, logic errors, and other defects. Although accurate tests should be a way to discover such bugs as early as possible, we may sometimes miss cases because of different factors such as time constraints or complexity. Therefore, as a Go developer, it\u2019s essential to make sure we avoid common bugs.
"},{"location":"chapter-1/#needless-complexity","title":"Needless complexity","text":"The next category of mistakes is related to unnecessary complexity. A significant part of software complexity comes from the fact that, as developers, we strive to think about imaginary futures. Instead of solving concrete problems right now, it can be tempting to build evolutionary software that could tackle whatever future use case arises. However, this leads to more drawbacks than benefits in most cases because it can make a codebase more complex to understand and reason about.
Getting back to Go, we can think of plenty of use cases where developers might be tempted to design abstractions for future needs, such as interfaces or generics. This book discusses topics where we should remain careful not to harm a codebase with needless complexity.
"},{"location":"chapter-1/#weaker-readability","title":"Weaker readability","text":"Another kind of mistake is to weaken readability. As Robert C. Martin wrote in his book Clean Code: A Handbook of Agile Software Craftsmanship, the ratio of time spent reading versus writing is well over 10 to 1. Most of us started to program on solo projects where readability wasn\u2019t that important. However, today\u2019s software engineering is programming with a time dimension: making sure we can still work with and maintain an application months, years, or perhaps even decades later.
When programming in Go, we can make many mistakes that can harm readability. These mistakes may include nested code, data type representations, or not using named result parameters in some cases. Throughout this book, we will learn how to write readable code and care for future readers (including our future selves).
"},{"location":"chapter-1/#suboptimal-or-unidiomatic-organization","title":"Suboptimal or unidiomatic organization","text":"Be it while working on a new project or because we acquire inaccurate reflexes, another type of mistake is organizing our code and a project suboptimally and unidiomatically. Such issues can make a project harder to reason about and maintain. This book covers some of these common mistakes in Go. For example, we\u2019ll look at how to structure a project and deal with utility packages or init functions. All in all, looking at these mistakes should help us organize our code and projects more efficiently and idiomatically.
"},{"location":"chapter-1/#lack-of-api-convenience","title":"Lack of API convenience","text":"Making common mistakes that weaken how convenient an API is for our clients is another type of mistake. If an API isn\u2019t user-friendly, it will be less expressive and, hence, harder to understand and more error-prone.
We can think about many situations such as overusing any types, using the wrong creational pattern to deal with options, or blindly applying standard practices from object-oriented programming that affect the usability of our APIs. This book covers common mistakes that prevent us from exposing convenient APIs for our users.
"},{"location":"chapter-1/#under-optimized-code","title":"Under-optimized code","text":"Under-optimized code is another type of mistake made by developers. It can happen for various reasons, such as not understanding language features or even a lack of fundamental knowledge. Performance is one of the most obvious impacts of this mistake, but not the only one.
We can think about optimizing code for other goals, such as accuracy. For example, this book provides some common techniques to ensure that floating-point operations are accurate. Meanwhile, we will cover plenty of cases that can negatively impact performance code because of poorly parallelized executions, not knowing how to reduce allocations, or the impacts of data alignment, for example. We will tackle optimization via different prisms.
"},{"location":"chapter-1/#lack-of-productivity","title":"Lack of productivity","text":"In most cases, what\u2019s the best language we can choose when working on a new project? The one we\u2019re the most productive with. Being comfortable with how a language works and exploiting it to get the best out of it is crucial to reach proficiency.
In this book, we will cover many cases and concrete examples that will help us to be more productive while working in Go. For instance, we\u2019ll look at writing efficient tests to ensure that our code works, relying on the standard library to be more effective, and getting the best out of the profiling tools and linters. Now, it\u2019s time to delve into those 100 common Go mistakes.
"},{"location":"chapter-1/#summary","title":"Summary","text":"J. S. Moser, H. S. Schroder, et al., \u201cMind Your Errors: Evidence for a Neural Mechanism Linking Growth Mindset to Adaptive Posterror Adjustments,\u201d Psychological Science, vol. 22, no. 12, pp. 1484\u20131489, Dec. 2011.\u00a0\u21a9
J. Metcalfe, \u201cLearning from Errors,\u201d Annual Review of Psychology, vol. 68, pp. 465\u2013489, Jan. 2017.\u00a0\u21a9
Synopsys, \u201cThe Cost of Poor Software Quality in the US: A 2020 Report.\u201d 2020. https://news.synopsys.com/2021-01-06-Synopsys-Sponsored-CISQ-Research-Estimates-Cost-of-Poor-Software-Quality-in-the-US-2-08-Trillion-in-2020.\u00a0\u21a9
Post
"},{"location":"external/#the-most-useful-book-for-a-go-programmer","title":"The Most Useful Book for a Go Programmer?","text":""},{"location":"external/#how-to-make-mistakes-in-go-go-time-190","title":"How to make mistakes in Go - Go Time #190","text":"Post
"},{"location":"external/#what-can-be-summarized-from-100-go-mistakes","title":"What can be summarized from 100 Go Mistakes?","text":"Post
"},{"location":"external/#book-review-100-go-mistakes-and-how-to-avoid-them_1","title":"Book review: 100 Go Mistakes and How to Avoid Them","text":"Post
"},{"location":"external/#chinese","title":"Chinese","text":""},{"location":"external/#100-go-mistakes-and-how-to-avoid-them","title":"\u6df1\u5ea6\u9605\u8bfb\u4e4b\u300a100 Go Mistakes and How to Avoid Them","text":"Post
"},{"location":"external/#100-go-mistakes","title":"100 Go Mistakes \u968f\u8bb0","text":"Post
"},{"location":"external/#go","title":"\u6211\u4e3a\u4ec0\u4e48\u653e\u5f03Go\u8bed\u8a00\uff1f","text":"Post
"},{"location":"external/#japanese","title":"Japanese","text":""},{"location":"external/#go100-go-mistakes-and-how-to-avoid-them","title":"\u6700\u8fd1\u8aad\u3093\u3060Go\u8a00\u8a9e\u306e\u672c\u306e\u7d39\u4ecb\uff1a100 Go Mistakes and How to Avoid Them","text":"Post
"},{"location":"external/#100-go-mistakes-and-how-to-avoid-them_1","title":"\u300e100 Go Mistakes and How to Avoid Them\u300f\u3092\u8aad\u3080","text":"Post
"},{"location":"external/#portuguese","title":"Portuguese","text":""},{"location":"external/#um-otimo-livro-para-programadores-go","title":"Um \u00d3TIMO livro para programadores Go","text":""},{"location":"ja/","title":"Go\u8a00\u8a9e\u3067\u3042\u308a\u304c\u3061\u306a\u9593\u9055\u3044","text":"\u3053\u306e\u30da\u30fc\u30b8\u306f\u300e100 Go Mistakes\u300f\u306e\u5185\u5bb9\u3092\u307e\u3068\u3081\u305f\u3082\u306e\u3067\u3059\u3002\u4e00\u65b9\u3067\u3001\u30b3\u30df\u30e5\u30cb\u30c6\u30a3\u306b\u958b\u304b\u308c\u305f\u30da\u30fc\u30b8\u3067\u3082\u3042\u308a\u307e\u3059\u3002\u300c\u3042\u308a\u304c\u3061\u306a\u9593\u9055\u3044\u300d\u304c\u65b0\u305f\u306b\u8ffd\u52a0\u3055\u308c\u308b\u3079\u304d\u3060\u3068\u304a\u8003\u3048\u3067\u3057\u305f\u3089 community mistake issue \u3092\u4f5c\u6210\u3057\u3066\u304f\u3060\u3055\u3044\u3002
JobsIs your company hiring? Sponsor the Japanese version of this repository and let a significant audience of Go developers (~1k unique visitors per week) know about your opportunities in this section.
\u6ce8\u610f\u73fe\u5728\u3001\u5927\u5e45\u306b\u591a\u304f\u306e\u30b3\u30f3\u30c6\u30f3\u30c4\u3092\u8ffd\u52a0\u3057\u3066\u5f37\u5316\u3057\u3066\u3044\u308b\u65b0\u3057\u3044\u30d0\u30fc\u30b8\u30e7\u30f3\u3092\u95b2\u89a7\u3057\u3066\u3044\u307e\u3059\u3002\u3053\u306e\u30d0\u30fc\u30b8\u30e7\u30f3\u306f\u307e\u3060\u958b\u767a\u4e2d\u3067\u3059\u3002\u554f\u984c\u3092\u898b\u3064\u3051\u305f\u5834\u5408\u306f\u3069\u3046\u305e\u6c17\u8efd\u306bPR\u3092\u4f5c\u6210\u3057\u3066\u304f\u3060\u3055\u3044\u3002
"},{"location":"ja/#_1","title":"\u30b3\u30fc\u30c9\u3068\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u69cb\u6210","text":""},{"location":"ja/#1","title":"\u610f\u56f3\u7684\u3067\u306a\u3044\u5909\u6570\u306e\u30b7\u30e3\u30c9\u30fc\u30a4\u30f3\u30b0 (#1)","text":"\u8981\u7d04\u5909\u6570\u306e\u30b7\u30e3\u30c9\u30fc\u30a4\u30f3\u30b0\u3092\u907f\u3051\u308b\u3053\u3068\u306f\u3001\u8aa4\u3063\u305f\u5909\u6570\u306e\u53c2\u7167\u3084\u8aad\u307f\u624b\u306e\u6df7\u4e71\u3092\u9632\u304e\u307e\u3059\u3002
\u5909\u6570\u306e\u30b7\u30e3\u30c9\u30fc\u30a4\u30f3\u30b0\u306f\u3001\u5909\u6570\u540d\u304c\u30d6\u30ed\u30c3\u30af\u5185\u3067\u518d\u5ba3\u8a00\u3055\u308c\u308b\u3053\u3068\u3067\u751f\u3058\u307e\u3059\u304c\u3001\u3053\u308c\u306f\u9593\u9055\u3044\u3092\u5f15\u304d\u8d77\u3053\u3057\u3084\u3059\u304f\u3057\u307e\u3059\u3002\u5909\u6570\u306e\u30b7\u30e3\u30c9\u30fc\u30a4\u30f3\u30b0\u3092\u7981\u6b62\u3059\u308b\u304b\u3069\u3046\u304b\u306f\u500b\u4eba\u306e\u597d\u307f\u306b\u3088\u308a\u307e\u3059\u3002\u305f\u3068\u3048\u3070\u3001\u30a8\u30e9\u30fc\u306b\u5bfe\u3057\u3066 err
\u306e\u3088\u3046\u306a\u65e2\u5b58\u306e\u5909\u6570\u540d\u3092\u518d\u5229\u7528\u3059\u308b\u3068\u4fbf\u5229\u306a\u5834\u5408\u304c\u3042\u308a\u307e\u3059\u3002\u3068\u306f\u3044\u3048\u3001\u30b3\u30fc\u30c9\u306f\u30b3\u30f3\u30d1\u30a4\u30eb\u3055\u308c\u305f\u3082\u306e\u306e\u3001\u5024\u3092\u53d7\u3051\u53d6\u3063\u305f\u5909\u6570\u304c\u4e88\u671f\u3057\u305f\u3082\u306e\u3067\u306f\u306a\u3044\u3068\u3044\u3046\u30b7\u30ca\u30ea\u30aa\u306b\u76f4\u9762\u3059\u308b\u53ef\u80fd\u6027\u304c\u3042\u308b\u305f\u3081\u3001\u539f\u5247\u3068\u3057\u3066\u5f15\u304d\u7d9a\u304d\u6ce8\u610f\u3092\u6255\u3046\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#2","title":"\u4e0d\u5fc5\u8981\u306b\u30cd\u30b9\u30c8\u3055\u308c\u305f\u30b3\u30fc\u30c9 (#2)","text":"\u8981\u7d04\u30cd\u30b9\u30c8\u304c\u6df1\u304f\u306a\u3089\u306a\u3044\u3088\u3046\u306b\u3057\u3001\u30cf\u30c3\u30d4\u30fc\u30d1\u30b9\u3092\u5de6\u5074\u306b\u63c3\u3048\u308b\u3053\u3068\u3067\u30e1\u30f3\u30bf\u30eb\u30b3\u30fc\u30c9\u30e2\u30c7\u30eb\u3092\u69cb\u7bc9\u3059\u308b\u3053\u3068\u304c\u5bb9\u6613\u306b\u306a\u308a\u307e\u3059\u3002
\u4e00\u822c\u7684\u306b\u3001\u95a2\u6570\u304c\u3088\u308a\u6df1\u3044\u30cd\u30b9\u30c8\u3092\u8981\u6c42\u3059\u308b\u307b\u3069\u3001\u8aad\u3093\u3067\u7406\u89e3\u3059\u308b\u3053\u3068\u304c\u3088\u308a\u8907\u96d1\u306b\u306a\u308a\u307e\u3059\u3002\u79c1\u305f\u3061\u306e\u30b3\u30fc\u30c9\u306e\u53ef\u8aad\u6027\u3092\u6700\u9069\u5316\u3059\u308b\u305f\u3081\u306b\u3001\u3053\u306e\u30eb\u30fc\u30eb\u306e\u9069\u7528\u65b9\u6cd5\u3092\u898b\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u3002
if
\u30d6\u30ed\u30c3\u30af\u304c\u8fd4\u3055\u308c\u308b\u3068\u304d\u3001\u3059\u3079\u3066\u306e\u5834\u5408\u306b\u304a\u3044\u3066 else
\u30d6\u30ed\u30c3\u30af\u3092\u7701\u7565\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002 \u305f\u3068\u3048\u3070\u3001\u6b21\u306e\u3088\u3046\u306b\u66f8\u304f\u3079\u304d\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u3002if foo() {\n // ...\n return true\n} else {\n // ...\n}\n
\u4ee3\u308f\u308a\u306b\u3001\u6b21\u306e\u3088\u3046\u306b else
\u30d6\u30ed\u30c3\u30af\u3092\u7701\u7565\u3057\u307e\u3059\u3002
if foo() {\n // ...\n return true\n}\n// ...\n
if s != \"\" {\n // ...\n} else {\n return errors.New(\"empty string\")\n}\n
\u3053\u3053\u3067\u306f\u3001\u7a7a\u306e s
\u304c\u30ce\u30f3\u30cf\u30c3\u30d4\u30fc\u30d1\u30b9\u3092\u8868\u3057\u307e\u3059\u3002\u3057\u305f\u304c\u3063\u3066\u3001\u6b21\u306e\u3088\u3046\u306b\u6761\u4ef6\u3092\u3072\u3063\u304f\u308a\u8fd4\u3059\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002
if s == \"\" {\n return errors.New(\"empty string\")\n}\n// ...\n
\u8aad\u307f\u3084\u3059\u3044\u30b3\u30fc\u30c9\u3092\u66f8\u304f\u3053\u3068\u306f\u3001\u3059\u3079\u3066\u306e\u958b\u767a\u8005\u306b\u3068\u3063\u3066\u91cd\u8981\u306a\u8ab2\u984c\u3067\u3059\u3002\u30cd\u30b9\u30c8\u3055\u308c\u305f\u30d6\u30ed\u30c3\u30af\u306e\u6570\u3092\u6e1b\u3089\u3059\u3088\u3046\u52aa\u3081\u3001\u30cf\u30c3\u30d4\u30fc\u30d1\u30b9\u3092\u5de6\u5074\u306b\u63c3\u3048\u3001\u3067\u304d\u308b\u3060\u3051\u65e9\u304f\u623b\u308b\u3053\u3068\u304c\u3001\u30b3\u30fc\u30c9\u306e\u53ef\u8aad\u6027\u3092\u5411\u4e0a\u3055\u305b\u308b\u5177\u4f53\u7684\u306a\u624b\u6bb5\u3067\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#init-3","title":"init\u95a2\u6570\u306e\u8aa4\u7528 (#3)","text":"\u8981\u7d04\u5909\u6570\u3092\u521d\u671f\u5316\u3059\u308b\u3068\u304d\u306f\u3001init\u95a2\u6570\u306e\u30a8\u30e9\u30fc\u51e6\u7406\u304c\u5236\u9650\u3055\u308c\u3066\u304a\u308a\u3001\u30b9\u30c6\u30fc\u30c8\u306e\u51e6\u7406\u3068\u30c6\u30b9\u30c8\u304c\u3088\u308a\u8907\u96d1\u306b\u306a\u308b\u3053\u3068\u306b\u6ce8\u610f\u3057\u3066\u304f\u3060\u3055\u3044\u3002\u307b\u3068\u3093\u3069\u306e\u5834\u5408\u3001\u521d\u671f\u5316\u306f\u7279\u5b9a\u306e\u95a2\u6570\u3068\u3057\u3066\u51e6\u7406\u3055\u308c\u308b\u3079\u304d\u3067\u3059\u3002
init\u95a2\u6570\u306f\u3001\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u30b9\u30c6\u30fc\u30c8\u3092\u521d\u671f\u5316\u3059\u308b\u305f\u3081\u306b\u4f7f\u7528\u3055\u308c\u308b\u95a2\u6570\u3067\u3059\u3002\u5f15\u6570\u3092\u53d6\u3089\u305a\u3001\u7d50\u679c\u3082\u8fd4\u3057\u307e\u305b\u3093\uff08 func()
\u95a2\u6570\uff09\u3002\u30d1\u30c3\u30b1\u30fc\u30b8\u304c\u521d\u671f\u5316\u3055\u308c\u308b\u3068\u3001\u30d1\u30c3\u30b1\u30fc\u30b8\u5185\u306e\u3059\u3079\u3066\u306e\u5b9a\u6570\u304a\u3088\u3073\u5909\u6570\u306e\u5ba3\u8a00\u304c\u8a55\u4fa1\u3055\u308c\u307e\u3059\u3002\u6b21\u306b\u3001init\u95a2\u6570\u304c\u5b9f\u884c\u3055\u308c\u307e\u3059\u3002
init\u95a2\u6570\u306f\u3044\u304f\u3064\u304b\u306e\u554f\u984c\u3092\u5f15\u304d\u8d77\u3053\u3059\u53ef\u80fd\u6027\u304c\u3042\u308a\u307e\u3059\u3002
init\u95a2\u6570\u306b\u306f\u6ce8\u610f\u304c\u5fc5\u8981\u3067\u3059\u3002\u305f\u3060\u3057\u3001\u9759\u7684\u69cb\u6210\u306e\u5b9a\u7fa9\u306a\u3069\u3001\u72b6\u6cc1\u306b\u3088\u3063\u3066\u306f\u5f79\u7acb\u3064\u5834\u5408\u304c\u3042\u308a\u307e\u3059\u3002\u305d\u308c\u4ee5\u5916\u306e\u307b\u3068\u3093\u3069\u306e\u5834\u5408\u3001\u521d\u671f\u5316\u51e6\u7406\u306f\u7279\u5b9a\u306e\u95a2\u6570\u3092\u901a\u3058\u3066\u884c\u308f\u308c\u308b\u3079\u304d\u3067\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#4","title":"\u30b2\u30c3\u30bf\u30fc\u3068\u30bb\u30c3\u30bf\u30fc\u306e\u4e71\u7528 (#4)","text":"\u8981\u7d04Go\u8a00\u8a9e\u3067\u306f\u3001\u6163\u7528\u7684\u306b\u30b2\u30c3\u30bf\u30fc\u3068\u30bb\u30c3\u30bf\u30fc\u306e\u4f7f\u7528\u3092\u5f37\u5236\u3059\u308b\u3053\u3068\u306f\u3042\u308a\u307e\u305b\u3093\u3002\u5b9f\u5229\u3092\u91cd\u8996\u3057\u3001\u52b9\u7387\u6027\u3068\u7279\u5b9a\u306e\u6163\u7fd2\u306b\u5f93\u3046\u3053\u3068\u3068\u306e\u9593\u306e\u9069\u5207\u306a\u30d0\u30e9\u30f3\u30b9\u3092\u898b\u3064\u3051\u308b\u3053\u3068\u304c\u3001\u9032\u3080\u3079\u304d\u9053\u3067\u3042\u308b\u306f\u305a\u3067\u3059\u3002
\u30c7\u30fc\u30bf\u306e\u30ab\u30d7\u30bb\u30eb\u5316\u3068\u306f\u3001\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u5024\u307e\u305f\u306f\u72b6\u614b\u3092\u96a0\u3059\u3053\u3068\u3092\u6307\u3057\u307e\u3059\u3002\u30b2\u30c3\u30bf\u30fc\u3068\u30bb\u30c3\u30bf\u30fc\u306f\u3001\u30a8\u30af\u30b9\u30dd\u30fc\u30c8\u3055\u308c\u3066\u3044\u306a\u3044\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u30d5\u30a3\u30fc\u30eb\u30c9\u306e\u4e0a\u306b\u30a8\u30af\u30b9\u30dd\u30fc\u30c8\u3055\u308c\u305f\u30e1\u30bd\u30c3\u30c9\u3092\u63d0\u4f9b\u3059\u308b\u3053\u3068\u3067\u30ab\u30d7\u30bb\u30eb\u5316\u3092\u53ef\u80fd\u306b\u3059\u308b\u624b\u6bb5\u3067\u3059\u3002
Go\u8a00\u8a9e\u3067\u306f\u3001\u4e00\u90e8\u306e\u8a00\u8a9e\u3067\u898b\u3089\u308c\u308b\u3088\u3046\u306a\u30b2\u30c3\u30bf\u30fc\u3068\u30bb\u30c3\u30bf\u30fc\u306e\u81ea\u52d5\u30b5\u30dd\u30fc\u30c8\u306f\u3042\u308a\u307e\u305b\u3093\u3002\u307e\u305f\u3001\u30b2\u30c3\u30bf\u30fc\u3068\u30bb\u30c3\u30bf\u30fc\u3092\u4f7f\u7528\u3057\u3066\u69cb\u9020\u4f53\u30d5\u30a3\u30fc\u30eb\u30c9\u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b\u3053\u3068\u306f\u5fc5\u9808\u3067\u3082\u6163\u7528\u7684\u3067\u3082\u3042\u308a\u307e\u305b\u3093\u3002\u5024\u3092\u3082\u305f\u3089\u3055\u306a\u3044\u69cb\u9020\u4f53\u306e\u30b2\u30c3\u30bf\u30fc\u3068\u30bb\u30c3\u30bf\u30fc\u3067\u30b3\u30fc\u30c9\u3092\u57cb\u3081\u308b\u3079\u304d\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u3002\u5b9f\u5229\u3092\u91cd\u8996\u3057\u3001\u4ed6\u306e\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u30d1\u30e9\u30c0\u30a4\u30e0\u3067\u6642\u306b\u306f\u8b70\u8ad6\u306e\u4f59\u5730\u304c\u306a\u3044\u3068\u8003\u3048\u3089\u308c\u3066\u3044\u308b\u6163\u7fd2\u306b\u5f93\u3046\u3053\u3068\u3068\u3001\u52b9\u7387\u6027\u3068\u306e\u9593\u306e\u9069\u5207\u306a\u30d0\u30e9\u30f3\u30b9\u3092\u898b\u3064\u3051\u308b\u3088\u3046\u52aa\u3081\u308b\u3079\u304d\u3067\u3059\u3002
Go\u8a00\u8a9e\u306f\u3001\u30b7\u30f3\u30d7\u30eb\u3055\u3092\u542b\u3080\u591a\u304f\u306e\u7279\u6027\u3092\u8003\u616e\u3057\u3066\u8a2d\u8a08\u3055\u308c\u305f\u72ec\u81ea\u306e\u8a00\u8a9e\u3067\u3042\u308b\u3053\u3068\u3092\u5fd8\u308c\u306a\u3044\u3067\u304f\u3060\u3055\u3044\u3002\u305f\u3060\u3057\u3001\u30b2\u30c3\u30bf\u30fc\u3068\u30bb\u30c3\u30bf\u30fc\u306e\u5fc5\u8981\u6027\u304c\u898b\u3064\u304b\u3063\u305f\u5834\u5408\u3001\u307e\u305f\u306f\u524d\u8ff0\u306e\u3088\u3046\u306b\u3001\u524d\u65b9\u4e92\u63db\u6027\u3092\u4fdd\u8a3c\u3057\u306a\u304c\u3089\u5c06\u6765\u306e\u5fc5\u8981\u6027\u304c\u4e88\u6e2c\u3055\u308c\u308b\u5834\u5408\u306f\u3001\u305d\u308c\u3089\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u306b\u554f\u984c\u306f\u3042\u308a\u307e\u305b\u3093\u3002
"},{"location":"ja/#5","title":"\u30a4\u30f3\u30bf\u30d5\u30a7\u30fc\u30b9\u6c5a\u67d3 (#5)","text":"\u8981\u7d04\u62bd\u8c61\u5316\u306f\u4f5c\u6210\u3055\u308c\u308b\u3079\u304d\u3082\u306e\u3067\u306f\u306a\u304f\u3001\u767a\u898b\u3055\u308c\u308b\u3079\u304d\u3082\u306e\u3067\u3059\u3002\u4e0d\u5fc5\u8981\u306a\u8907\u96d1\u3055\u3092\u907f\u3051\u308b\u305f\u3081\u306b\u3001\u30a4\u30f3\u30bf\u30d5\u30a7\u30fc\u30b9\u306f\u3001\u5fc5\u8981\u306b\u306a\u308b\u3068\u4e88\u6e2c\u3057\u305f\u3068\u304d\u3067\u306f\u306a\u304f\u3001\u5fc5\u8981\u306b\u306a\u3063\u305f\u3068\u304d\u306b\u4f5c\u6210\u3059\u308b\u304b\u3001\u5c11\u306a\u304f\u3068\u3082\u62bd\u8c61\u5316\u304c\u6709\u52b9\u3067\u3042\u308b\u3053\u3068\u3092\u8a3c\u660e\u3067\u304d\u308b\u5834\u5408\u306b\u4f5c\u6210\u3057\u3066\u304f\u3060\u3055\u3044\u3002
\u30a4\u30f3\u30bf\u30d5\u30a7\u30fc\u30b9\u306f\u3001\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u52d5\u4f5c\u3092\u6307\u5b9a\u3059\u308b\u65b9\u6cd5\u3092\u63d0\u4f9b\u3057\u307e\u3059\u3002\u8907\u6570\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u304c\u5b9f\u88c5\u3067\u304d\u308b\u5171\u901a\u9805\u3092\u62bd\u51fa\u3059\u308b\u305f\u3081\u306b\u3001\u30a4\u30f3\u30bf\u30d5\u30a7\u30fc\u30b9\u306f\u4f7f\u7528\u3055\u308c\u307e\u3059\u3002Go\u8a00\u8a9e\u306e\u30a4\u30f3\u30bf\u30d5\u30a7\u30fc\u30b9\u304c\u5927\u304d\u304f\u7570\u306a\u308b\u306e\u306f\u3001\u6697\u9ed9\u7684\u306b\u6e80\u305f\u3055\u308c\u308b\u3053\u3068\u3067\u3059\u3002\u30aa\u30d6\u30b8\u30a7\u30af\u30c8 X
\u304c\u30a4\u30f3\u30bf\u30d5\u30a7\u30fc\u30b9 Y
\u3092\u5b9f\u88c5\u3057\u3066\u3044\u308b\u3053\u3068\u3092\u793a\u3059 implements
\u306e\u3088\u3046\u306a\u660e\u793a\u7684\u306a\u30ad\u30fc\u30ef\u30fc\u30c9\u306f\u3042\u308a\u307e\u305b\u3093\u3002
\u4e00\u822c\u306b\u3001\u30a4\u30f3\u30bf\u30d5\u30a7\u30fc\u30b9\u304c\u4fa1\u5024\u3092\u3082\u305f\u3089\u3059\u3068\u8003\u3048\u3089\u308c\u308b\u4e3b\u8981\u306a\u4f7f\u7528\u4f8b\u306f\uff13\u3064\u3042\u308a\u307e\u3059\u3002\u305d\u308c\u306f\u3001\u5171\u901a\u306e\u52d5\u4f5c\u3092\u9664\u5916\u3059\u308b\u3001\u4f55\u3089\u304b\u306e\u5206\u96e2\u3092\u4f5c\u6210\u3059\u308b\u3001\u304a\u3088\u3073\u578b\u3092\u7279\u5b9a\u306e\u52d5\u4f5c\u306b\u5236\u9650\u3059\u308b\u3068\u3044\u3046\u3082\u306e\u3067\u3059\u3002\u305f\u3060\u3057\u3001\u3053\u306e\u30ea\u30b9\u30c8\u306f\u3059\u3079\u3066\u3092\u7db2\u7f85\u3057\u3066\u3044\u308b\u308f\u3051\u3067\u306f\u306a\u304f\u3001\u76f4\u9762\u3059\u308b\u72b6\u6cc1\u306b\u3088\u3063\u3066\u3082\u7570\u306a\u308a\u307e\u3059\u3002
\u591a\u304f\u306e\u5834\u5408\u3001\u30a4\u30f3\u30bf\u30d5\u30a7\u30fc\u30b9\u306f\u62bd\u8c61\u5316\u3059\u308b\u305f\u3081\u306b\u4f5c\u6210\u3055\u308c\u307e\u3059\u3002\u305d\u3057\u3066\u3001\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u3067\u62bd\u8c61\u5316\u3059\u308b\u3068\u304d\u306e\u4e3b\u306a\u6ce8\u610f\u70b9\u306f\u3001\u62bd\u8c61\u5316\u306f\u4f5c\u6210\u3055\u308c\u308b\u3079\u304d\u3067\u306f\u306a\u304f\u3001\u767a\u898b\u3055\u308c\u308b\u3079\u304d\u3067\u3042\u308b\u3068\u3044\u3046\u3053\u3068\u3092\u899a\u3048\u3066\u304a\u304f\u3053\u3068\u3067\u3059\u3002\u3059\u306a\u308f\u3061\u3001\u305d\u3046\u3059\u308b\u76f4\u63a5\u306e\u7406\u7531\u304c\u306a\u3044\u9650\u308a\u3001\u30b3\u30fc\u30c9\u5185\u3067\u62bd\u8c61\u5316\u3059\u3079\u304d\u3067\u306f\u306a\u3044\u3068\u3044\u3046\u3053\u3068\u3067\u3059\u3002\u30a4\u30f3\u30bf\u30d5\u30a7\u30fc\u30b9\u3092\u4f7f\u3063\u3066\u8a2d\u8a08\u3059\u308b\u306e\u3067\u306f\u306a\u304f\u3001\u5177\u4f53\u7684\u306a\u30cb\u30fc\u30ba\u3092\u5f85\u3064\u3079\u304d\u3067\u3059\u3002\u5225\u306e\u8a00\u3044\u65b9\u3092\u3059\u308c\u3070\u3001\u30a4\u30f3\u30bf\u30d5\u30a7\u30fc\u30b9\u306f\u5fc5\u8981\u306b\u306a\u308b\u3068\u4e88\u6e2c\u3057\u305f\u3068\u304d\u3067\u306f\u306a\u304f\u3001\u5fc5\u8981\u306b\u306a\u3063\u305f\u3068\u304d\u306b\u4f5c\u6210\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002 \u30a4\u30f3\u30bf\u30d5\u30a7\u30fc\u30b9\u306e\u904e\u5ea6\u306a\u4f7f\u7528\u3092\u3057\u305f\u5834\u5408\u306e\u4e3b\u306a\u554f\u984c\u306f\u4f55\u3067\u3057\u3087\u3046\u304b\u3002\u7b54\u3048\u306f\u3001\u30b3\u30fc\u30c9\u30d5\u30ed\u30fc\u304c\u3088\u308a\u8907\u96d1\u306b\u306a\u308b\u3053\u3068\u3067\u3059\u3002\u5f79\u306b\u7acb\u305f\u306a\u3044\u9593\u63a5\u53c2\u7167\u3092\u8ffd\u52a0\u3057\u3066\u3082\u4f55\u306e\u4fa1\u5024\u3082\u3042\u308a\u307e\u305b\u3093\u3002\u305d\u308c\u306f\u4fa1\u5024\u306e\u306a\u3044\u62bd\u8c61\u5316\u3092\u3059\u308b\u3053\u3068\u3067\u3001\u30b3\u30fc\u30c9\u3092\u8aad\u307f\u3001\u7406\u89e3\u3057\u3001\u63a8\u8ad6\u3059\u308b\u3053\u3068\u3092\u3055\u3089\u306b\u56f0\u96e3\u306b\u3057\u307e\u3059\u3002\u30a4\u30f3\u30bf\u30d5\u30a7\u30fc\u30b9\u3092\u8ffd\u52a0\u3059\u308b\u660e\u78ba\u306a\u7406\u7531\u304c\u306a\u304f\u3001\u30a4\u30f3\u30bf\u30d5\u30a7\u30fc\u30b9\u306b\u3088\u3063\u3066\u30b3\u30fc\u30c9\u304c\u3069\u306e\u3088\u3046\u306b\u6539\u5584\u3055\u308c\u308b\u304b\u304c\u4e0d\u660e\u77ad\u306a\u5834\u5408\u306f\u3001\u305d\u306e\u30a4\u30f3\u30bf\u30d5\u30a7\u30fc\u30b9\u306e\u76ee\u7684\u306b\u7570\u8b70\u3092\u5531\u3048\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u5b9f\u88c5\u3092\u76f4\u63a5\u547c\u3073\u51fa\u3059\u306e\u3082\u4e00\u3064\u306e\u624b\u3067\u3059\u3002
\u30b3\u30fc\u30c9\u5185\u3067\u62bd\u8c61\u5316\u3059\u308b\u3068\u304d\u306f\u6ce8\u610f\u304c\u5fc5\u8981\u3067\u3059\uff08\u62bd\u8c61\u5316\u306f\u4f5c\u6210\u3059\u308b\u306e\u3067\u306f\u306a\u304f\u3001\u767a\u898b\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\uff09\u3002\u5f8c\u3067\u5fc5\u8981\u306b\u306a\u308b\u53ef\u80fd\u6027\u304c\u3042\u308b\u3082\u306e\u3092\u8003\u616e\u3057\u3001\u5b8c\u74a7\u306a\u62bd\u8c61\u5316\u30ec\u30d9\u30eb\u3092\u63a8\u6e2c\u3057\u3066\u3001\u79c1\u305f\u3061\u30bd\u30d5\u30c8\u30a6\u30a7\u30a2\u958b\u767a\u8005\u306f\u30b3\u30fc\u30c9\u3092\u30aa\u30fc\u30d0\u30fc\u30a8\u30f3\u30b8\u30cb\u30a2\u30ea\u30f3\u30b0\u3059\u308b\u3053\u3068\u304c\u3088\u304f\u3042\u308a\u307e\u3059\u3002\u307b\u3068\u3093\u3069\u306e\u5834\u5408\u3001\u30b3\u30fc\u30c9\u304c\u4e0d\u5fc5\u8981\u306a\u62bd\u8c61\u5316\u3067\u6c5a\u67d3\u3055\u308c\u3001\u8aad\u307f\u306b\u304f\u304f\u306a\u308b\u305f\u3081\u3001\u3053\u306e\u30d7\u30ed\u30bb\u30b9\u306f\u907f\u3051\u308b\u3079\u304d\u3067\u3059\u3002
\u30ed\u30d6\u30fb\u30d1\u30a4\u30af
\u30a4\u30f3\u30bf\u30d5\u30a7\u30fc\u30b9\u3067\u30c7\u30b6\u30a4\u30f3\u3059\u308b\u306a\u3002\u30a4\u30f3\u30bf\u30d5\u30a7\u30fc\u30b9\u3092\u898b\u3064\u3051\u51fa\u305b\u3002
\u62bd\u8c61\u7684\u306b\u554f\u984c\u3092\u89e3\u6c7a\u3057\u3088\u3046\u3068\u3059\u308b\u306e\u3067\u306f\u306a\u304f\u3001\u4eca\u89e3\u6c7a\u3059\u3079\u304d\u3053\u3068\u3092\u89e3\u6c7a\u3057\u307e\u3057\u3087\u3046\u3002\u6700\u5f8c\u306b\u91cd\u8981\u306a\u3053\u3068\u3067\u3059\u304c\u3001\u30a4\u30f3\u30bf\u30d5\u30a7\u30fc\u30b9\u306b\u3088\u3063\u3066\u30b3\u30fc\u30c9\u304c\u3069\u306e\u3088\u3046\u306b\u6539\u5584\u3055\u308c\u308b\u304b\u304c\u4e0d\u660e\u77ad\u306a\u5834\u5408\u306f\u3001\u30b3\u30fc\u30c9\u3092\u7c21\u7d20\u5316\u3059\u308b\u305f\u3081\u306b\u30a4\u30f3\u30bf\u30d5\u30a7\u30fc\u30b9\u3092\u524a\u9664\u3059\u308b\u3053\u3068\u3092\u691c\u8a0e\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u3067\u3057\u3087\u3046\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#6","title":"\u751f\u7523\u8005\u5074\u306e\u30a4\u30f3\u30bf\u30d5\u30a7\u30fc\u30b9 (#6)","text":"\u8981\u7d04\u30a4\u30f3\u30bf\u30d5\u30a7\u30fc\u30b9\u3092\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u5074\u3067\u4fdd\u6301\u3059\u308b\u3053\u3068\u3067\u4e0d\u5fc5\u8981\u306a\u62bd\u8c61\u5316\u3092\u56de\u907f\u3067\u304d\u307e\u3059\u3002
Go\u8a00\u8a9e\u3067\u306f\u30a4\u30f3\u30bf\u30d5\u30a7\u30fc\u30b9\u304c\u6697\u9ed9\u7684\u306b\u6e80\u305f\u3055\u308c\u307e\u3059\u3002\u3053\u308c\u306f\u3001\u660e\u793a\u7684\u306a\u5b9f\u88c5\u3092\u6301\u3064\u8a00\u8a9e\u3068\u6bd4\u8f03\u3057\u3066\u5927\u304d\u306a\u5909\u5316\u3092\u3082\u305f\u3089\u3059\u50be\u5411\u304c\u3042\u308a\u307e\u3059\u3002\u307b\u3068\u3093\u3069\u306e\u5834\u5408\u3001\u5f93\u3046\u3079\u304d\u30a2\u30d7\u30ed\u30fc\u30c1\u306f\u524d\u306e\u30bb\u30af\u30b7\u30e7\u30f3\u3067\u8aac\u660e\u3057\u305f\u3082\u306e\u2015\u2015\u62bd\u8c61\u5316\u306f\u4f5c\u6210\u3059\u308b\u306e\u3067\u306f\u306a\u304f\u3001\u767a\u898b\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u2015\u2015\u306b\u4f3c\u3066\u3044\u307e\u3059\u3002\u3053\u308c\u306f\u3001\u3059\u3079\u3066\u306e\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u306b\u5bfe\u3057\u3066\u7279\u5b9a\u306e\u62bd\u8c61\u5316\u3092\u5f37\u5236\u3059\u308b\u306e\u306f\u751f\u7523\u8005\u306e\u5f79\u5272\u3067\u306f\u306a\u3044\u3053\u3068\u3092\u610f\u5473\u3057\u307e\u3059\u3002\u4ee3\u308f\u308a\u306b\u3001\u4f55\u3089\u304b\u306e\u5f62\u5f0f\u306e\u62bd\u8c61\u5316\u304c\u5fc5\u8981\u304b\u3069\u3046\u304b\u3092\u5224\u65ad\u3057\u3001\u305d\u306e\u30cb\u30fc\u30ba\u306b\u6700\u9069\u306a\u62bd\u8c61\u5316\u30ec\u30d9\u30eb\u3092\u6c7a\u5b9a\u3059\u308b\u306e\u306f\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u306e\u8cac\u4efb\u3067\u3059\u3002
\u307b\u3068\u3093\u3069\u306e\u5834\u5408\u3001\u30a4\u30f3\u30bf\u30d5\u30a7\u30fc\u30b9\u306f\u6d88\u8cbb\u8005\u5074\u306b\u5b58\u5728\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u305f\u3060\u3057\u3001\u7279\u5b9a\u306e\u72b6\u6cc1\uff08\u305f\u3068\u3048\u3070\u3001\u62bd\u8c61\u5316\u304c\u6d88\u8cbb\u8005\u306b\u3068\u3063\u3066\u5f79\u7acb\u3064\u3053\u3068\u304c\u308f\u304b\u3063\u3066\u3044\u308b\u2015\u2015\u4e88\u6e2c\u306f\u3057\u3066\u3044\u306a\u3044\u2015\u2015\u5834\u5408\uff09\u3067\u306f\u3001\u305d\u308c\u3092\u751f\u7523\u8005\u5074\u3067\u4f7f\u7528\u3057\u305f\u3044\u5834\u5408\u304c\u3042\u308a\u307e\u3059\u3002\u305d\u3046\u3057\u305f\u5834\u5408\u3001\u53ef\u80fd\u306a\u9650\u308a\u6700\u5c0f\u9650\u306b\u6291\u3048\u3001\u518d\u5229\u7528\u53ef\u80fd\u6027\u3092\u9ad8\u3081\u3001\u3088\u308a\u7c21\u5358\u306b\u69cb\u6210\u3067\u304d\u308b\u3088\u3046\u306b\u52aa\u3081\u308b\u3079\u304d\u3067\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#7","title":"\u30a4\u30f3\u30bf\u30d5\u30a7\u30fc\u30b9\u3092\u8fd4\u3059 (#7)","text":"\u8981\u7d04\u67d4\u8edf\u6027\u306b\u554f\u984c\u304c\u306a\u3044\u3088\u3046\u306b\u3059\u308b\u305f\u3081\u306b\u3001\u95a2\u6570\u306f\u307b\u3068\u3093\u3069\u306e\u5834\u5408\u3001\u30a4\u30f3\u30bf\u30d5\u30a7\u30fc\u30b9\u3067\u306f\u306a\u304f\u5177\u4f53\u7684\u200b\u200b\u306a\u5b9f\u88c5\u3092\u8fd4\u3059\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u9006\u306b\u3001\u95a2\u6570\u306f\u53ef\u80fd\u306a\u9650\u308a\u30a4\u30f3\u30bf\u30d5\u30a7\u30fc\u30b9\u3092\u53d7\u3051\u5165\u308c\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002
\u307b\u3068\u3093\u3069\u306e\u5834\u5408\u3001\u30a4\u30f3\u30bf\u30d5\u30a7\u30fc\u30b9\u3067\u306f\u306a\u304f\u5177\u4f53\u7684\u306a\u5b9f\u88c5\u3092\u8fd4\u3059\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u305d\u3046\u3067\u306a\u3044\u3068\u30d1\u30c3\u30b1\u30fc\u30b8\u306e\u4f9d\u5b58\u95a2\u4fc2\u306b\u3088\u308a\u8a2d\u8a08\u304c\u3044\u3063\u305d\u3046\u8907\u96d1\u306b\u306a\u308a\u3001\u3059\u3079\u3066\u306e\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u304c\u540c\u3058\u62bd\u8c61\u5316\u306b\u4f9d\u5b58\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u305f\u3081\u3001\u67d4\u8edf\u6027\u306b\u6b20\u3051\u308b\u53ef\u80fd\u6027\u304c\u3042\u308a\u307e\u3059\u3002\u7d50\u8ad6\u306f\u524d\u306e\u30bb\u30af\u30b7\u30e7\u30f3\u3068\u4f3c\u3066\u3044\u307e\u3059\u3002\u62bd\u8c61\u5316\u304c\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u306b\u3068\u3063\u3066\u5f79\u7acb\u3064\u3053\u3068\u304c\uff08\u4e88\u6e2c\u3055\u308c\u308b\u3067\u306f\u306a\u304f\uff09\u308f\u304b\u3063\u3066\u3044\u308b\u5834\u5408\u306f\u3001\u30a4\u30f3\u30bf\u30d5\u30a7\u30fc\u30b9\u3092\u8fd4\u3059\u3053\u3068\u3092\u691c\u8a0e\u3057\u3066\u3082\u3088\u3044\u3067\u3057\u3087\u3046\u3002\u305d\u308c\u4ee5\u5916\u306e\u5834\u5408\u306f\u3001\u62bd\u8c61\u5316\u3092\u5f37\u5236\u3059\u3079\u304d\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u3002\u305d\u308c\u3089\u306f\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u306b\u3088\u3063\u3066\u767a\u898b\u3055\u308c\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u4f55\u3089\u304b\u306e\u7406\u7531\u3067\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u304c\u5b9f\u88c5\u3092\u62bd\u8c61\u5316\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u5834\u5408\u3067\u3082\u3001\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u5074\u3067\u305d\u308c\u3092\u884c\u3046\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002
"},{"location":"ja/#any-8","title":"any
\u306f\u4f55\u3082\u8a00\u308f\u306a\u3044 (#8)","text":"\u8981\u7d04 json.Marshal
\u306a\u3069\u8003\u3048\u3046\u308b\u3059\u3079\u3066\u306e\u578b\u3092\u53d7\u3051\u5165\u308c\u308b\u304b\u8fd4\u3059\u5fc5\u8981\u304c\u3042\u308b\u5834\u5408\u306b\u306e\u307f any
\u3092\u4f7f\u7528\u3057\u3066\u304f\u3060\u3055\u3044\u3002\u305d\u308c\u4ee5\u5916\u306e\u5834\u5408\u3001any
\u306f\u610f\u5473\u306e\u3042\u308b\u60c5\u5831\u3092\u63d0\u4f9b\u305b\u305a\u3001\u547c\u3073\u51fa\u3057\u5143\u304c\u4efb\u610f\u306e\u30c7\u30fc\u30bf\u578b\u306e\u30e1\u30bd\u30c3\u30c9\u3092\u547c\u3073\u51fa\u3059\u3053\u3068\u3092\u8a31\u53ef\u3059\u308b\u305f\u3081\u3001\u30b3\u30f3\u30d1\u30a4\u30eb\u6642\u306b\u554f\u984c\u304c\u767a\u751f\u3059\u308b\u53ef\u80fd\u6027\u304c\u3042\u308a\u307e\u3059\u3002
any
\u578b\u306f\u3001\u8003\u3048\u3046\u308b\u3059\u3079\u3066\u306e\u578b\u3092\u53d7\u3051\u5165\u308c\u308b\u304b\u8fd4\u3059\u5fc5\u8981\u304c\u3042\u308b\u5834\u5408\uff08\u305f\u3068\u3048\u3070\u3001\u30de\u30fc\u30b7\u30e3\u30ea\u30f3\u30b0\u3084\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u306e\u5834\u5408\uff09\u306b\u5f79\u7acb\u3061\u307e\u3059\u3002\u539f\u5247\u3068\u3057\u3066\u30b3\u30fc\u30c9\u3092\u904e\u5ea6\u306b\u4e00\u822c\u5316\u3059\u308b\u3053\u3068\u306f\u4f55\u3068\u3057\u3066\u3082\u907f\u3051\u308b\u3079\u304d\u3067\u3059\u3002\u30b3\u30fc\u30c9\u306e\u8868\u73fe\u529b\u306a\u3069\u306e\u4ed6\u306e\u5074\u9762\u304c\u5411\u4e0a\u3059\u308b\u5834\u5408\u306f\u3001\u30b3\u30fc\u30c9\u3092\u5c11\u3057\u91cd\u8907\u3055\u305b\u305f\u307b\u3046\u304c\u826f\u3044\u3053\u3068\u3082\u3042\u308a\u307e\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#9","title":"\u30b8\u30a7\u30cd\u30ea\u30c3\u30af\u30b9\u3092\u3044\u3064\u4f7f\u7528\u3059\u308b\u3079\u304d\u304b\u7406\u89e3\u3057\u3066\u3044\u306a\u3044 (#9)","text":"\u8981\u7d04\u30b8\u30a7\u30cd\u30ea\u30c3\u30af\u30b9\u3068\u578b\u30d1\u30e9\u30e1\u30fc\u30bf\u30fc\u3092\u5229\u7528\u3059\u308b\u3053\u3068\u3067\u3001\u8981\u7d20\u3084\u52d5\u4f5c\u3092\u9664\u5916\u3059\u308b\u305f\u3081\u306e\u30dc\u30a4\u30e9\u30fc\u30d7\u30ec\u30fc\u30c8\u30b3\u30fc\u30c9\u3092\u907f\u3051\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u305f\u3060\u3057\u3001\u578b\u30d1\u30e9\u30e1\u30fc\u30bf\u306f\u6642\u671f\u5c1a\u65e9\u306b\u4f7f\u7528\u305b\u305a\u3001\u5177\u4f53\u7684\u306a\u5fc5\u8981\u6027\u304c\u308f\u304b\u3063\u305f\u5834\u5408\u306b\u306e\u307f\u4f7f\u7528\u3057\u3066\u304f\u3060\u3055\u3044\u3002\u305d\u3046\u3067\u306a\u3051\u308c\u3070\u3001\u4e0d\u5fc5\u8981\u306a\u62bd\u8c61\u5316\u3068\u8907\u96d1\u3055\u304c\u751f\u3058\u307e\u3059\u3002
\u30bb\u30af\u30b7\u30e7\u30f3\u5168\u6587\u306f\u3053\u3061\u3089\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#10","title":"\u578b\u306e\u57cb\u3081\u8fbc\u307f\u3067\u8d77\u3053\u308a\u3046\u308b\u554f\u984c\u3092\u628a\u63e1\u3057\u3066\u3044\u306a\u3044 (#10)","text":"\u8981\u7d04\u578b\u57cb\u3081\u8fbc\u307f\u3092\u4f7f\u7528\u3059\u308b\u3068\u3001\u30dc\u30a4\u30e9\u30fc\u30d7\u30ec\u30fc\u30c8\u30b3\u30fc\u30c9\u3092\u56de\u907f\u3059\u308b\u3053\u3068\u3082\u3067\u304d\u307e\u3059\u3002\u305f\u3060\u3057\u3001\u305d\u3046\u3059\u308b\u3053\u3068\u3067\u3001\u4e00\u90e8\u306e\u30d5\u30a3\u30fc\u30eb\u30c9\u3092\u975e\u8868\u793a\u306b\u3057\u3066\u304a\u304f\u5fc5\u8981\u304c\u3042\u308b\u5834\u5408\u306b\u554f\u984c\u304c\u767a\u751f\u3057\u306a\u3044\u3088\u3046\u306b\u3057\u3066\u304f\u3060\u3055\u3044\u3002
\u69cb\u9020\u4f53\u3092\u4f5c\u6210\u3059\u308b\u3068\u304d\u3001Go\u8a00\u8a9e\u306f\u578b\u3092\u57cb\u3081\u8fbc\u3080\u30aa\u30d7\u30b7\u30e7\u30f3\u3092\u63d0\u4f9b\u3057\u307e\u3059\u3002\u305f\u3060\u3057\u3001\u578b\u57cb\u3081\u8fbc\u307f\u306e\u610f\u5473\u3092\u3059\u3079\u3066\u7406\u89e3\u3057\u3066\u3044\u306a\u3044\u3068\u3001\u4e88\u60f3\u5916\u306e\u52d5\u4f5c\u304c\u767a\u751f\u3059\u308b\u53ef\u80fd\u6027\u304c\u3042\u308a\u307e\u3059\u3002\u3053\u306e\u30bb\u30af\u30b7\u30e7\u30f3\u3067\u306f\u3001\u578b\u3092\u57cb\u3081\u8fbc\u3080\u65b9\u6cd5\u3001\u305d\u308c\u304c\u3082\u305f\u3089\u3059\u3082\u306e\u3001\u304a\u3088\u3073\u8003\u3048\u3089\u308c\u308b\u554f\u984c\u306b\u3064\u3044\u3066\u898b\u3066\u3044\u304d\u307e\u3059\u3002
Go\u8a00\u8a9e\u3067\u306f\u3001\u540d\u524d\u306a\u3057\u3067\u5ba3\u8a00\u3055\u308c\u305f\u69cb\u9020\u4f53\u30d5\u30a3\u30fc\u30eb\u30c9\u306f\u3001\u57cb\u3081\u8fbc\u307f\u3068\u547c\u3070\u308c\u307e\u3059\u3002\u305f\u3068\u3048\u3070\u3001\u6b21\u306e\u3088\u3046\u306a\u3082\u306e\u3067\u3059\u3002
type Foo struct {\n Bar // \u57cb\u3081\u8fbc\u307f\u30d5\u30a3\u30fc\u30eb\u30c9\n}\n\ntype Bar struct {\n Baz int\n}\n
Foo
\u69cb\u9020\u4f53\u3067\u306f\u3001Bar
\u578b\u304c\u95a2\u9023\u4ed8\u3051\u3089\u308c\u305f\u540d\u524d\u306a\u3057\u3067\u5ba3\u8a00\u3055\u308c\u3066\u3044\u307e\u3059\u3002\u3057\u305f\u304c\u3063\u3066\u3001\u3053\u308c\u306f\u57cb\u3081\u8fbc\u307f\u30d5\u30a3\u30fc\u30eb\u30c9\u3067\u3059\u3002
\u57cb\u3081\u8fbc\u307f\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u3067\u3001\u57cb\u3081\u8fbc\u307f\u578b\u306e\u30d5\u30a3\u30fc\u30eb\u30c9\u3068\u30e1\u30bd\u30c3\u30c9\u306f\u6607\u683c\u3057\u307e\u3059\u3002Bar \u306b\u306f Baz \u30d5\u30a3\u30fc\u30eb\u30c9\u304c\u542b\u307e\u308c\u3066\u3044\u308b\u305f\u3081\u3001\u3053\u306e\u30d5\u30a3\u30fc\u30eb\u30c9\u306f Foo
\u306b\u6607\u683c\u3057\u307e\u3059\u3002\u3057\u305f\u304c\u3063\u3066\u3001Foo \u304b\u3089 Baz \u3092\u5229\u7528\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002
\u578b\u306e\u57cb\u3081\u8fbc\u307f\u306b\u3064\u3044\u3066\u4f55\u304c\u8a00\u3048\u308b\u3067\u3057\u3087\u3046\u304b\u3002\u307e\u305a\u3001\u3053\u308c\u304c\u5fc5\u8981\u306b\u306a\u308b\u3053\u3068\u306f\u307b\u3068\u3093\u3069\u306a\u304f\u3001\u30e6\u30fc\u30b9\u30b1\u30fc\u30b9\u304c\u4f55\u3067\u3042\u308c\u3001\u304a\u305d\u3089\u304f\u578b\u57cb\u3081\u8fbc\u307f\u306a\u3057\u3067\u3082\u540c\u69d8\u306b\u89e3\u6c7a\u3067\u304d\u308b\u3053\u3068\u3092\u610f\u5473\u3057\u307e\u3059\u3002\u578b\u306e\u57cb\u3081\u8fbc\u307f\u306f\u4e3b\u306b\u5229\u4fbf\u6027\u3092\u76ee\u7684\u3068\u3057\u3066\u4f7f\u7528\u3055\u308c\u307e\u3059\u3002\u307b\u3068\u3093\u3069\u306e\u5834\u5408\u3001\u305d\u308c\u306f\u52d5\u4f5c\u3092\u6607\u683c\u3059\u308b\u305f\u3081\u306b\u4f7f\u7528\u3055\u308c\u307e\u3059\u3002
\u578b\u57cb\u3081\u8fbc\u307f\u3092\u4f7f\u7528\u3059\u308b\u5834\u5408\u306f\u3001\u6b21\u306e 2 \u3064\u306e\u4e3b\u306a\u5236\u7d04\u3092\u5ff5\u982d\u306b\u7f6e\u304f\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002
Foo.Bar.Baz()
\u306e\u4ee3\u308f\u308a\u306b Foo.Baz()
\u306a\u3069\uff09\u3002 \u3053\u308c\u304c\u552f\u4e00\u306e\u6839\u62e0\u3067\u3042\u308b\u5834\u5408\u306f\u3001\u5185\u90e8\u578b\u3092\u57cb\u3081\u8fbc\u307e\u305a\u3001\u4ee3\u308f\u308a\u306b\u30d5\u30a3\u30fc\u30eb\u30c9\u3092\u4f7f\u3044\u307e\u3057\u3087\u3046\u3002\u3053\u308c\u3089\u306e\u5236\u7d04\u3092\u5ff5\u982d\u306b\u7f6e\u3044\u3066\u578b\u57cb\u3081\u8fbc\u307f\u3092\u610f\u8b58\u7684\u306b\u4f7f\u7528\u3059\u308b\u3068\u3001\u8ffd\u52a0\u306e\u8ee2\u9001\u30e1\u30bd\u30c3\u30c9\u306b\u3088\u308b\u30dc\u30a4\u30e9\u30fc\u30d7\u30ec\u30fc\u30c8\u30b3\u30fc\u30c9\u3092\u56de\u907f\u3059\u308b\u306e\u306b\u5f79\u7acb\u3061\u307e\u3059\u3002\u305f\u3060\u3057\u3001\u898b\u305f\u76ee\u3060\u3051\u3092\u76ee\u7684\u3068\u3057\u305f\u308a\u3001\u96a0\u3059\u3079\u304d\u8981\u7d20\u3092\u6607\u683c\u3057\u305f\u308a\u3057\u306a\u3044\u3088\u3046\u306b\u6ce8\u610f\u3057\u307e\u3057\u3087\u3046\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#functional-options-11","title":"Functional Options \u30d1\u30bf\u30fc\u30f3\u3092\u4f7f\u7528\u3057\u3066\u3044\u306a\u3044 (#11)","text":"\u8981\u7d04API \u306b\u9069\u3057\u305f\u65b9\u6cd5\u3067\u30aa\u30d7\u30b7\u30e7\u30f3\u3092\u4fbf\u5229\u306b\u51e6\u7406\u3059\u308b\u306b\u306f\u3001Functional Options \u30d1\u30bf\u30fc\u30f3\u3092\u4f7f\u7528\u3057\u307e\u3057\u3087\u3046\u3002
\u3055\u307e\u3056\u307e\u306a\u5b9f\u88c5\u65b9\u6cd5\u304c\u5b58\u5728\u3057\u3001\u591a\u5c11\u306e\u9055\u3044\u306f\u3042\u308a\u307e\u3059\u304c\u3001\u4e3b\u306a\u8003\u3048\u65b9\u306f\u6b21\u306e\u3068\u304a\u308a\u3067\u3059\u3002
type Option func(options *options)
\u30a8\u30e9\u30fc\u3092\u8fd4\u3059\u95a2\u6570\u3067\u3059\u3002\u305f\u3068\u3048\u3070\u3001WithPort
\u306f\u30dd\u30fc\u30c8\u3092\u8868\u3059 int
\u5f15\u6570\u3092\u53d7\u3051\u53d6\u308a\u3001options
\u69cb\u9020\u4f53\u306e\u66f4\u65b0\u65b9\u6cd5\u3092\u8868\u3059 Option
\u578b\u3092\u8fd4\u3057\u307e\u3059\u3002type options struct {\n port *int\n}\n\ntype Option func(options *options) error\n\nfunc WithPort(port int) Option {\n return func(options *options) error {\n if port < 0 {\n return errors.New(\"port should be positive\")\n }\n options.port = &port\n return nil\n }\n}\n\nfunc NewServer(addr string, opts ...Option) ( *http.Server, error) { <1>\n var options options <2>\n for _, opt := range opts { <3>\n err := opt(&options) <4>\n if err != nil {\n return nil, err\n }\n }\n\n// \u3053\u306e\u6bb5\u968e\u3067\u3001options \u69cb\u9020\u4f53\u304c\u69cb\u7bc9\u3055\u308c\u3001\u69cb\u6210\u304c\u542b\u307e\u308c\u307e\u3059\u3002\n// \u3057\u305f\u304c\u3063\u3066\u3001\u30dd\u30fc\u30c8\u8a2d\u5b9a\u306b\u95a2\u9023\u3059\u308b\u30ed\u30b8\u30c3\u30af\u3092\u5b9f\u88c5\u3067\u304d\u307e\u3059\u3002\n var port int\n if options.port == nil {\n port = defaultHTTPPort\n } else {\n if *options.port == 0 {\n port = randomPort()\n } else {\n port = *options.port\n }\n }\n\n // ...\n}\n
Functional Options \u30d1\u30bf\u30fc\u30f3\u306f\u3001\u30aa\u30d7\u30b7\u30e7\u30f3\u3092\u51e6\u7406\u3059\u308b\u305f\u3081\u306e\u624b\u8efd\u3067 API \u30d5\u30ec\u30f3\u30c9\u30ea\u30fc\u306a\u65b9\u6cd5\u3092\u63d0\u4f9b\u3057\u307e\u3059\u3002 Builder \u30d1\u30bf\u30fc\u30f3\u306f\u6709\u52b9\u306a\u30aa\u30d7\u30b7\u30e7\u30f3\u3067\u3059\u304c\u3001\u3044\u304f\u3064\u304b\u306e\u5c0f\u3055\u306a\u6b20\u70b9\uff08\u7a7a\u306e\u53ef\u80fd\u6027\u304c\u3042\u308b\u69cb\u6210\u69cb\u9020\u4f53\u3092\u6e21\u3055\u306a\u3051\u308c\u3070\u306a\u3089\u306a\u3044\u3001\u307e\u305f\u306f\u30a8\u30e9\u30fc\u3092\u51e6\u7406\u3059\u308b\u65b9\u6cd5\u304c\u3042\u307e\u308a\u4fbf\u5229\u3067\u306f\u306a\u3044\uff09\u304c\u3042\u308a\u3001\u3053\u306e\u7a2e\u306e\u554f\u984c\u306b\u304a\u3044\u3066 Functional Options \u30d1\u30bf\u30fc\u30f3\u304cGo\u8a00\u8a9e\u306b\u304a\u3051\u308b\u6163\u7528\u7684\u306a\u5bfe\u51e6\u65b9\u6cd5\u306b\u306a\u308b\u50be\u5411\u304c\u3042\u308a\u307e\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#12","title":"\u8aa4\u3063\u305f\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u69cb\u6210 (\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u69cb\u9020\u3068\u30d1\u30c3\u30b1\u30fc\u30b8\u69cb\u6210) (#12)","text":"\u5168\u4f53\u7684\u306a\u69cb\u6210\u306b\u95a2\u3057\u3066\u306f\u3001\u3055\u307e\u3056\u307e\u306a\u8003\u3048\u65b9\u304c\u3042\u308a\u307e\u3059\u3002\u305f\u3068\u3048\u3070\u3001\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u30b3\u30f3\u30c6\u30ad\u30b9\u30c8\u3054\u3068\u306b\u6574\u7406\u3059\u3079\u304d\u304b\u3001\u305d\u308c\u3068\u3082\u30ec\u30a4\u30e4\u30fc\u3054\u3068\u306b\u6574\u7406\u3059\u3079\u304d\u304b\u3001\u305d\u308c\u306f\u597d\u307f\u306b\u3088\u3063\u3066\u7570\u306a\u308a\u307e\u3059\u3002\u30b3\u30f3\u30c6\u30ad\u30b9\u30c8\uff08\u9867\u5ba2\u30b3\u30f3\u30c6\u30ad\u30b9\u30c8\u3001\u5951\u7d04\u30b3\u30f3\u30c6\u30ad\u30b9\u30c8\u306a\u3069\uff09\u3054\u3068\u306b\u30b3\u30fc\u30c9\u3092\u30b0\u30eb\u30fc\u30d7\u5316\u3059\u308b\u3053\u3068\u3092\u9078\u3076\u5834\u5408\u3082\u3042\u308c\u3070\u3001\u516d\u89d2\u5f62\u306e\u30a2\u30fc\u30ad\u30c6\u30af\u30c1\u30e3\u539f\u5247\u306b\u5f93\u3046\u3053\u3068\u3068\u3001\u6280\u8853\u5c64\u3054\u3068\u306b\u30b0\u30eb\u30fc\u30d7\u5316\u3059\u308b\u3053\u3068\u3092\u9078\u3076\u5834\u5408\u3082\u3042\u308a\u307e\u3059\u3002\u79c1\u305f\u3061\u304c\u884c\u3046\u6c7a\u5b9a\u304c\u4e00\u8cab\u3057\u3066\u3044\u308b\u9650\u308a\u3001\u305d\u308c\u304c\u30e6\u30fc\u30b9\u30b1\u30fc\u30b9\u306b\u9069\u5408\u3059\u308b\u306a\u3089\u3001\u305d\u308c\u304c\u9593\u9055\u3063\u3066\u3044\u308b\u3053\u3068\u306f\u3042\u308a\u307e\u305b\u3093\u3002
\u30d1\u30c3\u30b1\u30fc\u30b8\u306b\u95a2\u3057\u3066\u306f\u3001\u5f93\u3046\u3079\u304d\u30d9\u30b9\u30c8\u30d7\u30e9\u30af\u30c6\u30a3\u30b9\u304c\u8907\u6570\u3042\u308a\u307e\u3059\u3002\u307e\u305a\u3001\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u304c\u904e\u5ea6\u306b\u8907\u96d1\u306b\u306a\u308b\u53ef\u80fd\u6027\u304c\u3042\u308b\u305f\u3081\u3001\u6642\u671f\u5c1a\u65e9\u306a\u30d1\u30c3\u30b1\u30fc\u30b8\u5316\u306f\u907f\u3051\u308b\u3079\u304d\u3067\u3059\u3002\u5834\u5408\u306b\u3088\u3063\u3066\u306f\u3001\u5b8c\u74a7\u306a\u69cb\u9020\u3092\u6700\u521d\u304b\u3089\u7121\u7406\u306b\u4f5c\u308d\u3046\u3068\u3059\u308b\u3088\u308a\u3082\u3001\u5358\u7d14\u306a\u69cb\u6210\u3092\u4f7f\u7528\u3057\u3001\u305d\u306e\u5185\u5bb9\u3092\u7406\u89e3\u3057\u305f\u4e0a\u3067\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3092\u767a\u5c55\u3055\u305b\u308b\u307b\u3046\u304c\u826f\u3044\u5834\u5408\u304c\u3042\u308a\u307e\u3059\u3002 \u7c92\u5ea6\u3082\u8003\u616e\u3059\u3079\u304d\u91cd\u8981\u306a\u70b9\u3067\u3059\u3002 1 \u3064\u307e\u305f\u306f 2 \u3064\u306e\u30d5\u30a1\u30a4\u30eb\u3060\u3051\u3092\u542b\u3080\u6570\u5341\u306e\u30ca\u30ce\u30d1\u30c3\u30b1\u30fc\u30b8\u3092\u4f5c\u6210\u3059\u308b\u3053\u3068\u306f\u907f\u3051\u308b\u3079\u304d\u3067\u3059\u3002\u305d\u306e\u5834\u5408\u3001\u304a\u305d\u3089\u304f\u3053\u308c\u3089\u306e\u30d1\u30c3\u30b1\u30fc\u30b8\u9593\u306e\u8ad6\u7406\u7684\u306a\u63a5\u7d9a\u306e\u4e00\u90e8\u304c\u629c\u3051\u843d\u3061\u3001\u8aad\u307f\u624b\u306b\u3068\u3063\u3066\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u304c\u7406\u89e3\u3057\u306b\u304f\u304f\u306a\u308b\u304b\u3089\u3067\u3059\u3002\u9006\u306b\u3001\u30d1\u30c3\u30b1\u30fc\u30b8\u540d\u306e\u610f\u5473\u3092\u8584\u3081\u308b\u3088\u3046\u306a\u5de8\u5927\u306a\u30d1\u30c3\u30b1\u30fc\u30b8\u3082\u907f\u3051\u308b\u3079\u304d\u3067\u3059\u3002
\u30d1\u30c3\u30b1\u30fc\u30b8\u306e\u540d\u524d\u4ed8\u3051\u3082\u6ce8\u610f\u3057\u3066\u884c\u3046\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\uff08\u958b\u767a\u8005\u306a\u3089\uff09\u8ab0\u3082\u304c\u77e5\u3063\u3066\u3044\u308b\u3088\u3046\u306b\u3001\u540d\u524d\u3092\u4ed8\u3051\u308b\u306e\u306f\u96e3\u3057\u3044\u3067\u3059\u3002\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u304c Go \u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3092\u7406\u89e3\u3057\u3084\u3059\u3044\u3088\u3046\u306b\u3001\u30d1\u30c3\u30b1\u30fc\u30b8\u306b\u542b\u307e\u308c\u308b\u3082\u306e\u3067\u306f\u306a\u304f\u3001\u63d0\u4f9b\u3059\u308b\u3082\u306e\u306b\u57fa\u3065\u3044\u3066\u30d1\u30c3\u30b1\u30fc\u30b8\u306b\u540d\u524d\u3092\u4ed8\u3051\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u307e\u305f\u3001\u30cd\u30fc\u30df\u30f3\u30b0\u306b\u306f\u610f\u5473\u306e\u3042\u308b\u3082\u306e\u3092\u4ed8\u3051\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u3057\u305f\u304c\u3063\u3066\u3001\u30d1\u30c3\u30b1\u30fc\u30b8\u540d\u306f\u77ed\u304f\u3001\u7c21\u6f54\u3067\u3001\u8868\u73fe\u529b\u8c4a\u304b\u3067\u3001\u6163\u4f8b\u306b\u3088\u308a\u5358\u4e00\u306e\u5c0f\u6587\u5b57\u306b\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002
\u4f55\u3092\u30a8\u30af\u30b9\u30dd\u30fc\u30c8\u3059\u308b\u304b\u306b\u3064\u3044\u3066\u306e\u30eb\u30fc\u30eb\u306f\u975e\u5e38\u306b\u7c21\u5358\u3067\u3059\u3002\u30d1\u30c3\u30b1\u30fc\u30b8\u9593\u306e\u7d50\u5408\u3092\u6e1b\u3089\u3057\u3001\u30a8\u30af\u30b9\u30dd\u30fc\u30c8\u3055\u308c\u308b\u4e0d\u8981\u306a\u8981\u7d20\u3092\u975e\u8868\u793a\u306b\u3059\u308b\u305f\u3081\u306b\u3001\u30a8\u30af\u30b9\u30dd\u30fc\u30c8\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u3082\u306e\u3092\u3067\u304d\u308b\u9650\u308a\u6700\u5c0f\u9650\u306b\u6291\u3048\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u8981\u7d20\u3092\u30a8\u30af\u30b9\u30dd\u30fc\u30c8\u3059\u308b\u304b\u3069\u3046\u304b\u4e0d\u660e\u306a\u5834\u5408\u306f\u3001\u30c7\u30d5\u30a9\u30eb\u30c8\u3067\u30a8\u30af\u30b9\u30dd\u30fc\u30c8\u3057\u306a\u3044\u3088\u3046\u306b\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u5f8c\u3067\u30a8\u30af\u30b9\u30dd\u30fc\u30c8\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u3053\u3068\u304c\u5224\u660e\u3057\u305f\u5834\u5408\u306f\u3001\u30b3\u30fc\u30c9\u3092\u8abf\u6574\u3067\u304d\u307e\u3059\u3002\u307e\u305f\u3001\u69cb\u9020\u4f53\u3092 encoding/json \u3067\u30a2\u30f3\u30de\u30fc\u30b7\u30e3\u30ea\u30f3\u30b0\u3067\u304d\u308b\u3088\u3046\u306b\u30d5\u30a3\u30fc\u30eb\u30c9\u3092\u30a8\u30af\u30b9\u30dd\u30fc\u30c8\u3059\u308b\u306a\u3069\u3001\u3044\u304f\u3064\u304b\u306e\u4f8b\u5916\u306b\u3082\u7559\u610f\u3057\u3066\u304f\u3060\u3055\u3044\u3002
\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3092\u69cb\u6210\u3059\u308b\u306e\u306f\u7c21\u5358\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u304c\u3001\u3053\u308c\u3089\u306e\u30eb\u30fc\u30eb\u306b\u5f93\u3046\u3053\u3068\u3067\u7dad\u6301\u304c\u5bb9\u6613\u306b\u306a\u308a\u307e\u3059\u3002\u305f\u3060\u3057\u3001\u4fdd\u5b88\u6027\u3092\u5bb9\u6613\u306b\u3059\u308b\u305f\u3081\u306b\u306f\u4e00\u8cab\u6027\u3082\u91cd\u8981\u3067\u3042\u308b\u3053\u3068\u306b\u6ce8\u610f\u3057\u3066\u304f\u3060\u3055\u3044\u3002\u3057\u305f\u304c\u3063\u3066\u3001\u30b3\u30fc\u30c9\u30d9\u30fc\u30b9\u5185\u3067\u53ef\u80fd\u306a\u9650\u308a\u4e00\u8cab\u6027\u3092\u4fdd\u3064\u3088\u3046\u306b\u3057\u307e\u3057\u3087\u3046\u3002
\u88dc\u8db3Go \u30c1\u30fc\u30e0\u306f Go \u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306e\u7d44\u7e54\u5316/\u69cb\u9020\u5316\u306b\u95a2\u3059\u308b\u516c\u5f0f\u30ac\u30a4\u30c9\u30e9\u30a4\u30f3\u3092 2023 \u5e74\u306b\u767a\u884c\u3057\u307e\u3057\u305f\uff1a go.dev/doc/modules/layout
"},{"location":"ja/#13","title":"\u30e6\u30fc\u30c6\u30a3\u30ea\u30c6\u30a3\u30d1\u30c3\u30b1\u30fc\u30b8\u306e\u4f5c\u6210 (#13)","text":"\u8981\u7d04\u540d\u524d\u4ed8\u3051\u306f\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u8a2d\u8a08\u306e\u91cd\u8981\u306a\u90e8\u5206\u3067\u3059\u3002common
\u3001util
\u3001shared
\u306e\u3088\u3046\u306a\u30d1\u30c3\u30b1\u30fc\u30b8\u3092\u4f5c\u6210\u3057\u3066\u3082\u3001\u8aad\u307f\u624b\u306b\u305d\u308c\u307b\u3069\u306e\u4fa1\u5024\u3092\u3082\u305f\u3089\u3057\u307e\u305b\u3093\u3002\u3053\u306e\u3088\u3046\u306a\u30d1\u30c3\u30b1\u30fc\u30b8\u3092\u610f\u5473\u306e\u3042\u308b\u5177\u4f53\u7684\u306a\u30d1\u30c3\u30b1\u30fc\u30b8\u540d\u306b\u30ea\u30d5\u30a1\u30af\u30bf\u30ea\u30f3\u30b0\u3057\u307e\u3057\u3087\u3046\u3002
\u307e\u305f\u3001\u30d1\u30c3\u30b1\u30fc\u30b8\u306b\u542b\u307e\u308c\u308b\u3082\u306e\u3067\u306f\u306a\u304f\u3001\u30d1\u30c3\u30b1\u30fc\u30b8\u304c\u63d0\u4f9b\u3059\u308b\u3082\u306e\u306b\u57fa\u3065\u3044\u3066\u30d1\u30c3\u30b1\u30fc\u30b8\u306b\u540d\u524d\u3092\u4ed8\u3051\u308b\u3068\u3001\u305d\u306e\u8868\u73fe\u529b\u3092\u9ad8\u3081\u308b\u52b9\u7387\u7684\u306a\u65b9\u6cd5\u306b\u306a\u308b\u3053\u3068\u306b\u3082\u7559\u610f\u3057\u3066\u304f\u3060\u3055\u3044\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#14","title":"\u30d1\u30c3\u30b1\u30fc\u30b8\u540d\u306e\u885d\u7a81\u3092\u7121\u8996\u3059\u308b (#14)","text":"\u8981\u7d04\u6df7\u4e71\u3001\u3055\u3089\u306b\u306f\u30d0\u30b0\u306b\u3064\u306a\u304c\u308a\u304b\u306d\u306a\u3044\u3001\u5909\u6570\u3068\u30d1\u30c3\u30b1\u30fc\u30b8\u9593\u306e\u540d\u524d\u306e\u885d\u7a81\u3092\u56de\u907f\u3059\u308b\u305f\u3081\u306b\u3001\u305d\u308c\u305e\u308c\u306b\u4e00\u610f\u306e\u540d\u524d\u3092\u4f7f\u7528\u3057\u307e\u3057\u3087\u3046\u3002\u3053\u308c\u304c\u4e0d\u53ef\u80fd\u306a\u5834\u5408\u306f\u3001\u30a4\u30f3\u30dd\u30fc\u30c8\u30a8\u30a4\u30ea\u30a2\u30b9\u3092\u4f7f\u7528\u3057\u3066\u4fee\u98fe\u5b50\u3092\u5909\u66f4\u3057\u3066\u30d1\u30c3\u30b1\u30fc\u30b8\u540d\u3068\u5909\u6570\u540d\u3092\u533a\u5225\u3059\u308b\u304b\u3001\u3088\u308a\u826f\u3044\u540d\u524d\u3092\u8003\u3048\u3066\u304f\u3060\u3055\u3044\u3002
\u30d1\u30c3\u30b1\u30fc\u30b8\u306e\u885d\u7a81\u306f\u3001\u5909\u6570\u540d\u304c\u65e2\u5b58\u306e\u30d1\u30c3\u30b1\u30fc\u30b8\u540d\u3068\u885d\u7a81\u3059\u308b\u5834\u5408\u306b\u767a\u751f\u3057\u3001\u30d1\u30c3\u30b1\u30fc\u30b8\u306e\u518d\u5229\u7528\u304c\u59a8\u3052\u3089\u308c\u307e\u3059\u3002\u66d6\u6627\u3055\u3092\u907f\u3051\u308b\u305f\u3081\u306b\u3001\u5909\u6570\u540d\u306e\u885d\u7a81\u3092\u9632\u3050\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u885d\u7a81\u304c\u767a\u751f\u3057\u305f\u5834\u5408\u306f\u3001\u5225\u306e\u610f\u5473\u306e\u3042\u308b\u540d\u524d\u3092\u898b\u3064\u3051\u308b\u304b\u3001\u30a4\u30f3\u30dd\u30fc\u30c8\u30a8\u30a4\u30ea\u30a2\u30b9\u3092\u4f7f\u7528\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002
"},{"location":"ja/#15","title":"\u30b3\u30fc\u30c9\u306e\u6587\u7ae0\u5316\u304c\u884c\u308f\u308c\u3066\u3044\u306a\u3044 (#15)","text":"\u8981\u7d04\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u3068\u30e1\u30f3\u30c6\u30ca\u304c\u30b3\u30fc\u30c9\u306e\u610f\u56f3\u3092\u7406\u89e3\u3067\u304d\u308b\u3088\u3046\u306b\u3001\u30a8\u30af\u30b9\u30dd\u30fc\u30c8\u3055\u308c\u305f\u8981\u7d20\u3092\u6587\u7ae0\u5316\u3057\u307e\u3057\u3087\u3046\u3002
\u6587\u7ae0\u5316\u306f\u30b3\u30fc\u30c7\u30a3\u30f3\u30b0\u306e\u91cd\u8981\u306a\u5074\u9762\u3067\u3059\u3002\u3053\u308c\u306b\u3088\u308a\u3001\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u304c API \u3092\u3088\u308a\u7c21\u5358\u306b\u4f7f\u7528\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u304c\u3001\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306e\u7dad\u6301\u306b\u3082\u5f79\u7acb\u3061\u307e\u3059\u3002Go\u8a00\u8a9e\u3067\u306f\u3001\u30b3\u30fc\u30c9\u3092\u6163\u7528\u7684\u306a\u3082\u306e\u306b\u3059\u308b\u305f\u3081\u306b\u3001\u3044\u304f\u3064\u304b\u306e\u30eb\u30fc\u30eb\u306b\u5f93\u3046\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002
\u307e\u305a\u3001\u30a8\u30af\u30b9\u30dd\u30fc\u30c8\u3055\u308c\u305f\u3059\u3079\u3066\u306e\u8981\u7d20\u3092\u6587\u7ae0\u5316\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u69cb\u9020\u3001\u30a4\u30f3\u30bf\u30d5\u30a7\u30fc\u30b9\u3001\u95a2\u6570\u306a\u3069\u3001\u30a8\u30af\u30b9\u30dd\u30fc\u30c8\u3059\u308b\u5834\u5408\u306f\u6587\u7ae0\u5316\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u6163\u4f8b\u3068\u3057\u3066\u3001\u30a8\u30af\u30b9\u30dd\u30fc\u30c8\u3055\u308c\u305f\u8981\u7d20\u306e\u540d\u524d\u304b\u3089\u59cb\u307e\u308b\u30b3\u30e1\u30f3\u30c8\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002
\u6163\u4f8b\u3068\u3057\u3066\u3001\u5404\u30b3\u30e1\u30f3\u30c8\u306f\u53e5\u8aad\u70b9\u3067\u7d42\u308f\u308b\u5b8c\u5168\u306a\u6587\u3067\u3042\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u307e\u305f\u3001\u95a2\u6570\uff08\u307e\u305f\u306f\u30e1\u30bd\u30c3\u30c9\uff09\u3092\u6587\u7ae0\u5316\u3059\u308b\u3068\u304d\u306f\u3001\u95a2\u6570\u304c\u3069\u306e\u3088\u3046\u306b\u5b9f\u884c\u3059\u308b\u304b\u3067\u306f\u306a\u304f\u3001\u305d\u306e\u95a2\u6570\u304c\u4f55\u3092\u5b9f\u884c\u3059\u308b\u3064\u3082\u308a\u3067\u3042\u308b\u304b\u3092\u5f37\u8abf\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u3053\u3068\u306b\u3082\u7559\u610f\u3057\u3066\u304f\u3060\u3055\u3044\u3002\u3053\u308c\u306f\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u3067\u306f\u306a\u304f\u3001\u95a2\u6570\u3068\u30b3\u30e1\u30f3\u30c8\u306b\u3064\u3044\u3066\u3067\u3059\u3002\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u306f\u7406\u60f3\u7684\u306b\u306f\u3001\u5229\u7528\u8005\u304c\u30a8\u30af\u30b9\u30dd\u30fc\u30c8\u3055\u308c\u305f\u8981\u7d20\u306e\u4f7f\u7528\u65b9\u6cd5\u3092\u7406\u89e3\u3059\u308b\u305f\u3081\u306b\u30b3\u30fc\u30c9\u3092\u898b\u308b\u5fc5\u8981\u304c\u306a\u3044\u307b\u3069\u5341\u5206\u306a\u60c5\u5831\u3092\u63d0\u4f9b\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002
\u5909\u6570\u307e\u305f\u306f\u5b9a\u6570\u3092\u6587\u7ae0\u5316\u3059\u308b\u5834\u5408\u3001\u305d\u306e\u76ee\u7684\u3068\u5185\u5bb9\u3068\u3044\u3046 2 \u3064\u306e\u5074\u9762\u3092\u4f1d\u3048\u308b\u3053\u3068\u304c\u91cd\u8981\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002\u524d\u8005\u306f\u3001\u5916\u90e8\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u306b\u3068\u3063\u3066\u5f79\u7acb\u3064\u3088\u3046\u306b\u3001\u30b3\u30fc\u30c9\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u3068\u3057\u3066\u5b58\u5728\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u305f\u3060\u3057\u3001\u5f8c\u8005\u306f\u5fc5\u305a\u3057\u3082\u516c\u958b\u3055\u308c\u308b\u3079\u304d\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u3002
\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u3068\u30e1\u30f3\u30c6\u30ca\u304c\u30d1\u30c3\u30b1\u30fc\u30b8\u306e\u76ee\u7684\u3092\u7406\u89e3\u3067\u304d\u308b\u3088\u3046\u306b\u3001\u5404\u30d1\u30c3\u30b1\u30fc\u30b8\u3092\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u3059\u308b\u5fc5\u8981\u3082\u3042\u308a\u307e\u3059\u3002\u6163\u4f8b\u3068\u3057\u3066\u3001\u30b3\u30e1\u30f3\u30c8\u306f //Package
\u3067\u59cb\u307e\u308a\u3001\u305d\u306e\u5f8c\u306b\u30d1\u30c3\u30b1\u30fc\u30b8\u540d\u304c\u7d9a\u304d\u307e\u3059\u3002\u30d1\u30c3\u30b1\u30fc\u30b8\u30b3\u30e1\u30f3\u30c8\u306e\u6700\u521d\u306e\u884c\u306f\u3001\u30d1\u30c3\u30b1\u30fc\u30b8\u306b\u8868\u793a\u3055\u308c\u308b\u305f\u3081\u7c21\u6f54\u306b\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u305d\u3057\u3066\u3001\u6b21\u306e\u884c\u306b\u5fc5\u8981\u306a\u60c5\u5831\u3092\u3059\u3079\u3066\u5165\u529b\u3057\u307e\u3059\u3002
\u30b3\u30fc\u30c9\u3092\u6587\u7ae0\u5316\u3059\u308b\u3053\u3068\u304c\u5236\u7d04\u306b\u306a\u308b\u3079\u304d\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u3002\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u3084\u30e1\u30f3\u30c6\u30ca\u304c\u30b3\u30fc\u30c9\u306e\u610f\u56f3\u3092\u7406\u89e3\u3059\u308b\u306e\u306b\u5f79\u7acb\u3064\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002
"},{"location":"ja/#16","title":"\u30ea\u30f3\u30bf\u30fc\u3092\u4f7f\u7528\u3057\u3066\u306a\u3044 (#16)","text":"\u8981\u7d04\u30b3\u30fc\u30c9\u306e\u54c1\u8cea\u3068\u4e00\u8cab\u6027\u3092\u5411\u4e0a\u3055\u305b\u308b\u306b\u306f\u3001\u30ea\u30f3\u30bf\u30fc\u3068\u30d5\u30a9\u30fc\u30de\u30c3\u30bf\u30fc\u3092\u4f7f\u7528\u3057\u307e\u3057\u3087\u3046
\u30ea\u30f3\u30bf\u30fc\u306f\u3001\u30b3\u30fc\u30c9\u3092\u5206\u6790\u3057\u3066\u30a8\u30e9\u30fc\u3092\u691c\u51fa\u3059\u308b\u81ea\u52d5\u30c4\u30fc\u30eb\u3067\u3059\u3002\u3053\u306e\u30bb\u30af\u30b7\u30e7\u30f3\u306e\u76ee\u7684\u306f\u3001\u65e2\u5b58\u306e\u30ea\u30f3\u30bf\u30fc\u306e\u5b8c\u5168\u306a\u30ea\u30b9\u30c8\u3092\u63d0\u4f9b\u3059\u308b\u3053\u3068\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u3002\u305d\u3046\u3057\u305f\u5834\u5408\u3001\u3059\u3050\u306b\u4f7f\u3044\u7269\u306b\u306a\u3089\u306a\u304f\u306a\u3063\u3066\u3057\u307e\u3046\u304b\u3089\u3067\u3059\u3002\u305f\u3060\u3057\u3001\u307b\u3068\u3093\u3069\u306e Go \u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306b\u30ea\u30f3\u30bf\u30fc\u304c\u4e0d\u53ef\u6b20\u3067\u3042\u308b\u3068\u3044\u3046\u3053\u3068\u306f\u7406\u89e3\u3057\u3001\u899a\u3048\u3066\u304a\u304d\u307e\u3057\u3087\u3046\u3002
\u30ea\u30f3\u30bf\u30fc\u306e\u307b\u304b\u306b\u3001\u30b3\u30fc\u30c9\u30b9\u30bf\u30a4\u30eb\u3092\u4fee\u6b63\u3059\u308b\u305f\u3081\u306b\u30b3\u30fc\u30c9\u30d5\u30a9\u30fc\u30de\u30c3\u30bf\u30fc\u3082\u4f7f\u7528\u3057\u307e\u3057\u3087\u3046\u3002\u4ee5\u4e0b\u306b\u3001\u3044\u304f\u3064\u304b\u306e\u30b3\u30fc\u30c9\u30d5\u30a9\u30fc\u30de\u30c3\u30bf\u30fc\u3092\u793a\u3057\u307e\u3059\u3002
\u307b\u304b\u306b golangci-lint (https://github.com/golangci/golangci-lint) \u3068\u3044\u3046\u3082\u306e\u304c\u3042\u308a\u307e\u3059\u3002\u3053\u308c\u306f\u3001\u591a\u304f\u306e\u4fbf\u5229\u306a\u30ea\u30f3\u30bf\u30fc\u3084\u30d5\u30a9\u30fc\u30de\u30c3\u30bf\u30fc\u306e\u4e0a\u306b\u30d5\u30a1\u30b5\u30fc\u30c9\u3092\u63d0\u4f9b\u3059\u308b\u30ea\u30f3\u30c6\u30a3\u30f3\u30b0\u30c4\u30fc\u30eb\u3067\u3059\u3002\u307e\u305f\u3001\u30ea\u30f3\u30bf\u30fc\u3092\u4e26\u5217\u5b9f\u884c\u3057\u3066\u5206\u6790\u901f\u5ea6\u3092\u5411\u4e0a\u3055\u305b\u308b\u3053\u3068\u304c\u3067\u304d\u3001\u975e\u5e38\u306b\u4fbf\u5229\u3067\u3059\u3002
\u30ea\u30f3\u30bf\u30fc\u3068\u30d5\u30a9\u30fc\u30de\u30c3\u30bf\u30fc\u306f\u3001\u30b3\u30fc\u30c9\u30d9\u30fc\u30b9\u306e\u54c1\u8cea\u3068\u4e00\u8cab\u6027\u3092\u5411\u4e0a\u3055\u305b\u308b\u5f37\u529b\u306a\u65b9\u6cd5\u3067\u3059\u3002\u6642\u9593\u3092\u304b\u3051\u3066\u3069\u308c\u3092\u4f7f\u7528\u3059\u3079\u304d\u304b\u3092\u7406\u89e3\u3057\u3001\u305d\u308c\u3089\u306e\u5b9f\u884c\uff08 CI \u3084 Git \u30d7\u30ea\u30b3\u30df\u30c3\u30c8\u30d5\u30c3\u30af\u306a\u3069\uff09\u3092\u81ea\u52d5\u5316\u3057\u307e\u3057\u3087\u3046\u3002
"},{"location":"ja/#_2","title":"\u30c7\u30fc\u30bf\u578b","text":""},{"location":"ja/#8-17","title":"8 \u9032\u6570\u30ea\u30c6\u30e9\u30eb\u3067\u6df7\u4e71\u3092\u62db\u3044\u3066\u3057\u307e\u3046 (#17)","text":"\u8981\u7d04\u65e2\u5b58\u306e\u30b3\u30fc\u30c9\u3092\u8aad\u3080\u3068\u304d\u306f\u3001 0
\u3067\u59cb\u307e\u308b\u6574\u6570\u30ea\u30c6\u30e9\u30eb\u304c 8 \u9032\u6570\u3067\u3042\u308b\u3053\u3068\u306b\u7559\u610f\u3057\u3066\u304f\u3060\u3055\u3044\u3002\u307e\u305f\u3001\u63a5\u982d\u8f9e 0o
\u3092\u4ed8\u3051\u308b\u3053\u3068\u30678\u9032\u6570\u3067\u3042\u308b\u3053\u3068\u3092\u660e\u78ba\u306b\u3057\u3001\u8aad\u307f\u3084\u3059\u3055\u3092\u5411\u4e0a\u3055\u305b\u307e\u3057\u3087\u3046\u3002
8 \u9032\u6570\u306f 0 \u3067\u59cb\u307e\u308a\u307e\u3059\uff08\u305f\u3068\u3048\u3070\u3001010
\u306f 10 \u9032\u6570\u306e 8 \u306b\u76f8\u5f53\u3057\u307e\u3059\uff09\u3002\u53ef\u8aad\u6027\u3092\u5411\u4e0a\u3055\u305b\u3001\u5c06\u6765\u306e\u30b3\u30fc\u30c9\u30ea\u30fc\u30c0\u30fc\u306e\u6f5c\u5728\u7684\u306a\u9593\u9055\u3044\u3092\u56de\u907f\u3059\u308b\u306b\u306f\u3001 0o
\u63a5\u982d\u8f9e\u3092\u4f7f\u7528\u3057\u3066 8 \u9032\u6570\u3067\u3042\u308b\u3053\u3068\u3092\u660e\u3089\u304b\u306b\u3057\u307e\u3057\u3087\u3046\uff08\u4f8b: 0o10
\uff09\u3002
\u4ed6\u306e\u6574\u6570\u30ea\u30c6\u30e9\u30eb\u8868\u73fe\u306b\u3082\u6ce8\u610f\u3057\u3066\u304f\u3060\u3055\u3044\u3002
0b
\u3042\u308b\u3044\u306f 0B
\u3092\u4f7f\u7528\u3057\u307e\u3059\uff08\u305f\u3068\u3048\u3070\u3001 0b
\u306f 10 \u9032\u6570\u306e 4 \u306b\u76f8\u5f53\u3057\u307e\u3059\uff090x
\u3042\u308b\u3044\u306f 0X
\u3092\u4f7f\u7528\u3057\u307e\u3059\uff08\u305f\u3068\u3048\u3070\u3001 0xF
\u306f 10 \u9032\u6570\u306e 15 \u306b\u76f8\u5f53\u3057\u307e\u3059\uff09\u3002 i
\u3092\u4f7f\u7528\u3057\u307e\u3059\uff08\u305f\u3068\u3048\u3070\u3001 3i
\uff09\u8aad\u307f\u3084\u3059\u304f\u3059\u308b\u305f\u3081\u306b\u3001\u533a\u5207\u308a\u6587\u5b57\u3068\u3057\u3066\u30a2\u30f3\u30c0\u30fc\u30b9\u30b3\u30a2\uff08 _ \uff09\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u3082\u3067\u304d\u307e\u3059\u3002\u305f\u3068\u3048\u3070\u3001 10 \u5104\u306f 1_000_000_000
\u306e\u3088\u3046\u306b\u66f8\u304f\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u30a2\u30f3\u30c0\u30fc\u30b9\u30b3\u30a2\u306f 0b)00_00_01
\u306e\u3088\u3046\u306b\u4ed6\u306e\u8868\u73fe\u3068\u4f75\u7528\u3059\u308b\u3053\u3068\u3082\u3067\u304d\u307e\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#18","title":"\u6574\u6570\u30aa\u30fc\u30d0\u30fc\u30d5\u30ed\u30fc\u3092\u7121\u8996\u3057\u3066\u3044\u308b (#18)","text":"\u8981\u7d04Go\u8a00\u8a9e\u3067\u306f\u6574\u6570\u306e\u30aa\u30fc\u30d0\u30fc\u30d5\u30ed\u30fc\u3068\u30a2\u30f3\u30c0\u30fc\u30d5\u30ed\u30fc\u304c\u88cf\u5074\u3067\u51e6\u7406\u3055\u308c\u308b\u305f\u3081\u3001\u305d\u308c\u3089\u3092\u30ad\u30e3\u30c3\u30c1\u3059\u308b\u72ec\u81ea\u306e\u95a2\u6570\u3092\u5b9f\u88c5\u3067\u304d\u307e\u3059\u3002
Go\u8a00\u8a9e\u3067\u306f\u3001\u30b3\u30f3\u30d1\u30a4\u30eb\u6642\u306b\u691c\u51fa\u3067\u304d\u308b\u6574\u6570\u30aa\u30fc\u30d0\u30fc\u30d5\u30ed\u30fc\u306b\u3088\u3063\u3066\u30b3\u30f3\u30d1\u30a4\u30eb\u30a8\u30e9\u30fc\u304c\u751f\u6210\u3055\u308c\u307e\u3059\u3002\u305f\u3068\u3048\u3070\u3001\u6b21\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002
var counter int32 = math.MaxInt32 + 1\n
constant 2147483648 overflows int32\n
\u305f\u3060\u3057\u3001\u5b9f\u884c\u6642\u306b\u306f\u3001\u6574\u6570\u306e\u30aa\u30fc\u30d0\u30fc\u30d5\u30ed\u30fc\u307e\u305f\u306f\u30a2\u30f3\u30c0\u30fc\u30d5\u30ed\u30fc\u306f\u767a\u751f\u3057\u307e\u305b\u3093\u3002\u3053\u308c\u306b\u3088\u3063\u3066\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u30d1\u30cb\u30c3\u30af\u304c\u767a\u751f\u3059\u308b\u3053\u3068\u306f\u3042\u308a\u307e\u305b\u3093\u3002\u3053\u306e\u52d5\u4f5c\u306f\u3084\u3063\u304b\u3044\u306a\u30d0\u30b0\uff08\u305f\u3068\u3048\u3070\u3001\u8ca0\u306e\u7d50\u679c\u306b\u3064\u306a\u304c\u308b\u6574\u6570\u306e\u5897\u5206\u3084\u6b63\u306e\u6574\u6570\u306e\u52a0\u7b97\u306a\u3069\uff09\u306b\u3064\u306a\u304c\u308b\u53ef\u80fd\u6027\u304c\u3042\u308b\u305f\u3081\u3001\u982d\u306b\u5165\u308c\u3066\u304a\u304f\u3053\u3068\u304c\u91cd\u8981\u3067\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#19","title":"\u6d6e\u52d5\u5c0f\u6570\u70b9\u3092\u7406\u89e3\u3057\u3066\u3044\u306a\u3044 (#19)","text":"\u8981\u7d04\u7279\u5b9a\u306e\u30c7\u30eb\u30bf\u5185\u3067\u6d6e\u52d5\u5c0f\u6570\u70b9\u6bd4\u8f03\u3092\u884c\u3046\u3068\u3001\u30b3\u30fc\u30c9\u306e\u79fb\u690d\u6027\u3092\u78ba\u4fdd\u3067\u304d\u307e\u3059\u3002\u52a0\u7b97\u307e\u305f\u306f\u6e1b\u7b97\u3092\u5b9f\u884c\u3059\u308b\u3068\u304d\u306f\u3001\u7cbe\u5ea6\u3092\u5411\u4e0a\u3055\u305b\u308b\u305f\u3081\u306b\u3001\u540c\u7a0b\u5ea6\u306e\u5927\u304d\u3055\u306e\u6f14\u7b97\u3092\u30b0\u30eb\u30fc\u30d7\u5316\u3057\u3066\u304f\u3060\u3055\u3044\u3002\u307e\u305f\u3001\u4e57\u7b97\u3068\u9664\u7b97\u306f\u52a0\u7b97\u3068\u6e1b\u7b97\u306e\u524d\u306b\u5b9f\u884c\u3057\u3066\u304f\u3060\u3055\u3044\u3002
Go\u8a00\u8a9e\u306b\u306f\u3001\uff08\u865a\u6570\u3092\u9664\u3044\u305f\u5834\u5408\uff09 float32
\u3068 float64
\u3068\u3044\u3046 2 \u3064\u306e\u6d6e\u52d5\u5c0f\u6570\u70b9\u578b\u304c\u3042\u308a\u307e\u3059\u3002\u6d6e\u52d5\u5c0f\u6570\u70b9\u306e\u6982\u5ff5\u306f\u3001\u5c0f\u6570\u5024\u3092\u8868\u73fe\u3067\u304d\u306a\u3044\u3068\u3044\u3046\u6574\u6570\u306e\u5927\u304d\u306a\u554f\u984c\u3092\u89e3\u6c7a\u3059\u308b\u305f\u3081\u306b\u767a\u660e\u3055\u308c\u307e\u3057\u305f\u3002\u4e88\u60f3\u5916\u306e\u4e8b\u614b\u3092\u907f\u3051\u308b\u305f\u3081\u306b\u3001\u6d6e\u52d5\u5c0f\u6570\u70b9\u6f14\u7b97\u306f\u5b9f\u969b\u306e\u6f14\u7b97\u306e\u8fd1\u4f3c\u3067\u3042\u308b\u3053\u3068\u3092\u77e5\u3063\u3066\u304a\u304f\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002
\u305d\u306e\u305f\u3081\u306b\u3001\u4e57\u7b97\u306e\u4f8b\u3092\u898b\u3066\u307f\u307e\u3057\u3087\u3046\u3002
var n float32 = 1.0001\nfmt.Println(n * n)\n
\u3053\u306e\u30b3\u30fc\u30c9\u306b\u304a\u3044\u3066\u306f 1.0001 * 1.0001 = 1.00020001 \u3068\u3044\u3046\u7d50\u679c\u304c\u51fa\u529b\u3055\u308c\u308b\u3053\u3068\u3092\u671f\u5f85\u3059\u308b\u3068\u601d\u3044\u307e\u3059\u3002\u3057\u304b\u3057\u306a\u304c\u3089\u3001\u307b\u3068\u3093\u3069\u306e x86 \u30d7\u30ed\u30bb\u30c3\u30b5\u3067\u306f\u3001\u4ee3\u308f\u308a\u306b 1.0002 \u304c\u51fa\u529b\u3055\u308c\u307e\u3059\u3002
Go\u8a00\u8a9e\u306e float32
\u304a\u3088\u3073 float64
\u578b\u306f\u8fd1\u4f3c\u5024\u3067\u3042\u308b\u305f\u3081\u3001\u3044\u304f\u3064\u304b\u306e\u30eb\u30fc\u30eb\u3092\u5ff5\u982d\u306b\u7f6e\u304f\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#20","title":"\u30b9\u30e9\u30a4\u30b9\u306e\u9577\u3055\u3068\u5bb9\u91cf\u3092\u7406\u89e3\u3057\u3066\u3044\u306a\u3044 (#20)","text":"\u8981\u7d04Go \u958b\u767a\u8005\u306a\u3089\u3070\u3001\u30b9\u30e9\u30a4\u30b9\u306e\u9577\u3055\u3068\u5bb9\u91cf\u306e\u9055\u3044\u3092\u7406\u89e3\u3059\u308b\u3079\u304d\u3067\u3059\u3002\u30b9\u30e9\u30a4\u30b9\u306e\u9577\u3055\u306f\u30b9\u30e9\u30a4\u30b9\u5185\u306e\u4f7f\u7528\u53ef\u80fd\u306a\u8981\u7d20\u306e\u6570\u3067\u3042\u308a\u3001\u30b9\u30e9\u30a4\u30b9\u306e\u5bb9\u91cf\u306f\u30d0\u30c3\u30ad\u30f3\u30b0\u914d\u5217\u5185\u306e\u8981\u7d20\u306e\u6570\u3067\u3059\u3002
\u30bb\u30af\u30b7\u30e7\u30f3\u5168\u6587\u306f\u3053\u3061\u3089\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#21","title":"\u975e\u52b9\u7387\u306a\u30b9\u30e9\u30a4\u30b9\u306e\u521d\u671f\u5316 (#21)","text":"\u8981\u7d04\u30b9\u30e9\u30a4\u30b9\u3092\u4f5c\u6210\u3059\u308b\u3068\u304d\u3001\u9577\u3055\u304c\u3059\u3067\u306b\u308f\u304b\u3063\u3066\u3044\u308b\u5834\u5408\u306f\u3001\u6307\u5b9a\u3055\u308c\u305f\u9577\u3055\u307e\u305f\u306f\u5bb9\u91cf\u3067\u30b9\u30e9\u30a4\u30b9\u3092\u521d\u671f\u5316\u3057\u307e\u3057\u3087\u3046\u3002\u3053\u308c\u306b\u3088\u308a\u3001\u5272\u308a\u5f53\u3066\u306e\u6570\u304c\u6e1b\u308a\u3001\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u304c\u5411\u4e0a\u3057\u307e\u3059\u3002
make
\u3092\u4f7f\u7528\u3057\u3066\u30b9\u30e9\u30a4\u30b9\u3092\u521d\u671f\u5316\u3059\u308b\u3068\u304d\u306b\u3001\u9577\u3055\u3068\u30aa\u30d7\u30b7\u30e7\u30f3\u306e\u5bb9\u91cf\u3092\u6307\u5b9a\u3067\u304d\u307e\u3059\u3002\u3053\u308c\u3089\u306e\u30d1\u30e9\u30e1\u30fc\u30bf\u306e\u4e21\u65b9\u306b\u9069\u5207\u306a\u5024\u3092\u6e21\u3059\u3053\u3068\u304c\u9069\u5f53\u3067\u3042\u308b\u306b\u3082\u304b\u304b\u308f\u3089\u305a\u3001\u305d\u308c\u3092\u5fd8\u308c\u308b\u306e\u306f\u3088\u304f\u3042\u308b\u9593\u9055\u3044\u3067\u3059\u3002\u5b9f\u969b\u3001\u8907\u6570\u306e\u30b3\u30d4\u30fc\u304c\u5fc5\u8981\u306b\u306a\u308a\u3001\u4e00\u6642\u7684\u306a\u30d0\u30c3\u30ad\u30f3\u30b0\u914d\u5217\u3092\u30af\u30ea\u30fc\u30f3\u30a2\u30c3\u30d7\u3059\u308b\u305f\u3081\u306b GC \u306b\u8ffd\u52a0\u306e\u52b4\u529b\u304c\u304b\u304b\u308b\u53ef\u80fd\u6027\u304c\u3042\u308a\u307e\u3059\u3002\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u306e\u89b3\u70b9\u304b\u3089\u8a00\u3048\u3070\u3001Go \u30e9\u30f3\u30bf\u30a4\u30e0\u306b\u624b\u3092\u5dee\u3057\u4f38\u3079\u306a\u3044\u7406\u7531\u306f\u3042\u308a\u307e\u305b\u3093\u3002
\u30aa\u30d7\u30b7\u30e7\u30f3\u306f\u3001\u6307\u5b9a\u3055\u308c\u305f\u5bb9\u91cf\u307e\u305f\u306f\u6307\u5b9a\u3055\u308c\u305f\u9577\u3055\u306e\u30b9\u30e9\u30a4\u30b9\u3092\u5272\u308a\u5f53\u3066\u308b\u3053\u3068\u3067\u3059\u3002 \u3053\u308c\u3089 2 \u3064\u306e\u89e3\u6c7a\u7b56\u306e\u3046\u3061\u30012 \u756a\u76ee\u306e\u89e3\u6c7a\u7b56\u306e\u65b9\u304c\u308f\u305a\u304b\u306b\u9ad8\u901f\u3067\u3042\u308b\u50be\u5411\u304c\u3042\u308b\u3053\u3068\u304c\u308f\u304b\u308a\u307e\u3057\u305f\u3002\u305f\u3060\u3057\u3001\u7279\u5b9a\u306e\u5bb9\u91cf\u3068\u8ffd\u52a0\u3092\u4f7f\u7528\u3059\u308b\u3068\u3001\u5834\u5408\u306b\u3088\u3063\u3066\u306f\u5b9f\u88c5\u3068\u8aad\u307f\u53d6\u308a\u304c\u5bb9\u6613\u306b\u306a\u308b\u3053\u3068\u304c\u3042\u308a\u307e\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#nil-22","title":"nil \u3068\u7a7a\u306e\u30b9\u30e9\u30a4\u30b9\u3092\u6df7\u540c\u3057\u3066\u3044\u308b (#22)","text":"\u8981\u7d04encoding/json
\u3084 reflect
\u30d1\u30c3\u30b1\u30fc\u30b8\u306a\u3069\u3092\u4f7f\u7528\u3059\u308b\u3068\u304d\u306b\u3088\u304f\u3042\u308b\u6df7\u4e71\u3092\u907f\u3051\u308b\u305f\u3081\u306b\u306f\u3001nil \u30b9\u30e9\u30a4\u30b9\u3068\u7a7a\u306e\u30b9\u30e9\u30a4\u30b9\u306e\u9055\u3044\u3092\u7406\u89e3\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u3069\u3061\u3089\u3082\u9577\u3055\u30bc\u30ed\u3001\u5bb9\u91cf\u30bc\u30ed\u306e\u30b9\u30e9\u30a4\u30b9\u3067\u3059\u304c\u3001\u5272\u308a\u5f53\u3066\u3092\u5fc5\u8981\u3068\u3057\u306a\u3044\u306e\u306f nil \u30b9\u30e9\u30a4\u30b9\u3060\u3051\u3067\u3059\u3002
Go\u8a00\u8a9e\u3067\u306f\u3001nil \u3068\u7a7a\u306e\u30b9\u30e9\u30a4\u30b9\u306f\u533a\u5225\u3055\u308c\u307e\u3059\u3002nil \u30b9\u30e9\u30a4\u30b9\u306f nil
\u306b\u7b49\u3057\u3044\u306e\u306b\u5bfe\u3057\u3001\u7a7a\u306e\u30b9\u30e9\u30a4\u30b9\u306e\u9577\u3055\u306f\u30bc\u30ed\u3067\u3059\u3002nil \u30b9\u30e9\u30a4\u30b9\u306f\u7a7a\u3067\u3059\u304c\u3001\u7a7a\u306e\u30b9\u30e9\u30a4\u30b9\u306f\u5fc5\u305a\u3057\u3082nil
\u3067\u3042\u308b\u3068\u306f\u9650\u308a\u307e\u305b\u3093\u3002\u4e00\u65b9\u3001nil \u30b9\u30e9\u30a4\u30b9\u306b\u306f\u5272\u308a\u5f53\u3066\u306f\u5fc5\u8981\u3042\u308a\u307e\u305b\u3093\u3002\u3053\u306e\u30bb\u30af\u30b7\u30e7\u30f3\u5168\u4f53\u3092\u901a\u3057\u3066\u3001\u4ee5\u4e0b\u306e\u65b9\u6cd5\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u306b\u3088\u3063\u3066\u3001\u72b6\u6cc1\u306b\u5fdc\u3058\u3066\u30b9\u30e9\u30a4\u30b9\u3092\u521d\u671f\u5316\u3059\u308b\u3053\u3068\u3092\u898b\u3066\u304d\u307e\u3057\u305f\u3002
var s []string
[]string(nil)
make([]string, length)
\u8981\u7d20\u306a\u3057\u3067\u30b9\u30e9\u30a4\u30b9\u3092\u521d\u671f\u5316\u3059\u308b\u5834\u5408\u3001\u6700\u5f8c\u306e\u30aa\u30d7\u30b7\u30e7\u30f3 []string{}
\u306f\u907f\u3051\u308b\u3079\u304d\u3067\u3059\u3002\u6700\u5f8c\u306b\u3001\u4e88\u60f3\u5916\u306e\u52d5\u4f5c\u3092\u9632\u3050\u305f\u3081\u306b\u3001\u4f7f\u7528\u3059\u308b\u30e9\u30a4\u30d6\u30e9\u30ea\u304c nil \u3068\u7a7a\u306e\u30b9\u30e9\u30a4\u30b9\u3092\u533a\u5225\u3057\u3066\u3044\u308b\u304b\u3069\u3046\u304b\u3092\u78ba\u8a8d\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#23","title":"\u30b9\u30e9\u30a4\u30b9\u304c\u7a7a\u304b\u3069\u3046\u304b\u3092\u9069\u5207\u306b\u78ba\u8a8d\u3057\u306a\u3044 (#23)","text":"\u8981\u7d04\u30b9\u30e9\u30a4\u30b9\u306b\u8981\u7d20\u304c\u542b\u307e\u308c\u3066\u3044\u306a\u3044\u3053\u3068\u3092\u78ba\u8a8d\u3059\u308b\u306b\u306f\u3001\u305d\u306e\u9577\u3055\u3092\u78ba\u8a8d\u3057\u307e\u3057\u3087\u3046\u3002\u3053\u308c\u306f\u3001\u30b9\u30e9\u30a4\u30b9\u304c nil
\u3067\u3042\u308b\u304b\u7a7a\u3067\u3042\u308b\u304b\u306b\u95a2\u4fc2\u306a\u304f\u6a5f\u80fd\u3057\u307e\u3059\u3002\u30de\u30c3\u30d7\u306b\u3064\u3044\u3066\u3082\u540c\u69d8\u3067\u3059\u3002\u660e\u78ba\u306a API \u3092\u8a2d\u8a08\u3059\u308b\u306b\u306f\u3001nil \u30b9\u30e9\u30a4\u30b9\u3068\u7a7a\u306e\u30b9\u30e9\u30a4\u30b9\u3092\u533a\u5225\u3057\u306a\u3044\u3067\u304f\u3060\u3055\u3044\u3002
\u30b9\u30e9\u30a4\u30b9\u306b\u8981\u7d20\u304c\u3042\u308b\u304b\u3069\u3046\u304b\u3092\u5224\u65ad\u3059\u308b\u306b\u306f\u3001\u30b9\u30e9\u30a4\u30b9\u304c nil \u304b\u3069\u3046\u304b\u3001\u307e\u305f\u306f\u305d\u306e\u9577\u3055\u304c 0 \u306b\u7b49\u3057\u3044\u304b\u3069\u3046\u304b\u3092\u78ba\u8a8d\u3059\u308b\u3053\u3068\u3067\u5224\u65ad\u3067\u304d\u307e\u3059\u3002\u30b9\u30e9\u30a4\u30b9\u304c\u7a7a\u3067\u3042\u308b\u5834\u5408\u3068\u30b9\u30e9\u30a4\u30b9\u304c nil \u3067\u3042\u308b\u5834\u5408\u306e\u4e21\u65b9\u3092\u30ab\u30d0\u30fc\u3067\u304d\u308b\u305f\u3081\u3001\u9577\u3055\u3092\u78ba\u304b\u3081\u308b\u3053\u3068\u304c\u6700\u826f\u306e\u65b9\u6cd5\u3067\u3059\u3002
\u4e00\u65b9\u3001\u30a4\u30f3\u30bf\u30d5\u30a7\u30fc\u30b9\u3092\u8a2d\u8a08\u3059\u308b\u3068\u304d\u306f\u3001\u8efd\u5fae\u306a\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u30a8\u30e9\u30fc\u3092\u8d77\u3053\u3055\u306a\u3044\u3088\u3046 nil \u30b9\u30e9\u30a4\u30b9\u3068\u7a7a\u306e\u30b9\u30e9\u30a4\u30b9\u3092\u533a\u5225\u3057\u306a\u3044\u3088\u3046\u306b\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u30b9\u30e9\u30a4\u30b9\u3092\u8fd4\u3059\u3068\u304d\u306b\u3001nil \u307e\u305f\u306f\u7a7a\u306e\u30b9\u30e9\u30a4\u30b9\u3092\u8fd4\u3059\u304b\u3069\u3046\u304b\u306f\u3001\u610f\u5473\u7684\u306b\u3082\u6280\u8853\u7684\u306b\u3082\u9055\u3044\u306f\u3042\u308a\u307e\u305b\u3093\u3002\u30b3\u30fc\u30e9\u30fc\u306b\u3068\u3063\u3066\u306f\u3069\u3061\u3089\u3082\u540c\u3058\u3053\u3068\u3092\u610f\u5473\u3059\u308b\u306f\u305a\u3067\u3059\u3002\u3053\u306e\u539f\u7406\u306f\u30de\u30c3\u30d7\u3067\u3082\u540c\u3058\u3067\u3059\u3002\u30de\u30c3\u30d7\u304c\u7a7a\u304b\u3069\u3046\u304b\u3092\u78ba\u8a8d\u3059\u308b\u306b\u306f\u3001\u305d\u308c\u304c nil \u304b\u3069\u3046\u304b\u3067\u306f\u306a\u304f\u3001\u305d\u306e\u9577\u3055\u3092\u78ba\u8a8d\u3057\u307e\u3057\u3087\u3046\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#24","title":"\u30b9\u30e9\u30a4\u30b9\u306e\u30b3\u30d4\u30fc\u3092\u6b63\u3057\u304f\u4f5c\u6210\u3057\u3066\u3044\u306a\u3044 (#24)","text":"\u8981\u7d04\u7d44\u307f\u8fbc\u307f\u95a2\u6570 copy
\u3092\u4f7f\u7528\u3057\u3066\u3042\u308b\u30b9\u30e9\u30a4\u30b9\u3092\u5225\u306e\u30b9\u30e9\u30a4\u30b9\u306b\u30b3\u30d4\u30fc\u3059\u308b\u306b\u306f\u3001\u30b3\u30d4\u30fc\u3055\u308c\u308b\u8981\u7d20\u306e\u6570\u304c 2 \u3064\u306e\u30b9\u30e9\u30a4\u30b9\u306e\u9577\u3055\u306e\u9593\u306e\u6700\u5c0f\u5024\u306b\u76f8\u5f53\u3059\u308b\u3053\u3068\u306b\u6ce8\u610f\u3057\u3066\u304f\u3060\u3055\u3044\u3002
\u8981\u7d20\u3092\u3042\u308b\u30b9\u30e9\u30a4\u30b9\u304b\u3089\u5225\u306e\u30b9\u30e9\u30a4\u30b9\u306b\u30b3\u30d4\u30fc\u3059\u308b\u64cd\u4f5c\u306f\u3001\u304b\u306a\u308a\u983b\u7e41\u306b\u884c\u308f\u308c\u307e\u3059\u3002\u30b3\u30d4\u30fc\u3092\u4f7f\u7528\u3059\u308b\u5834\u5408\u3001\u30b3\u30d4\u30fc\u5148\u306b\u30b3\u30d4\u30fc\u3055\u308c\u308b\u8981\u7d20\u306e\u6570\u306f 2 \u3064\u306e\u30b9\u30e9\u30a4\u30b9\u306e\u9577\u3055\u306e\u9593\u306e\u6700\u5c0f\u5024\u306b\u76f8\u5f53\u3059\u308b\u3053\u3068\u306b\u6ce8\u610f\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u307e\u305f\u3001\u30b9\u30e9\u30a4\u30b9\u3092\u30b3\u30d4\u30fc\u3059\u308b\u305f\u3081\u306e\u4ed6\u306e\u4ee3\u66ff\u624b\u6bb5\u304c\u5b58\u5728\u3059\u308b\u3053\u3068\u306b\u3082\u7559\u610f\u3057\u3066\u304f\u3060\u3055\u3044\u3002\u305d\u306e\u305f\u3081\u3001\u30b3\u30fc\u30c9\u30d9\u30fc\u30b9\u3067\u305d\u308c\u3089\u3092\u898b\u3064\u3051\u3066\u3082\u9a5a\u304f\u3053\u3068\u306f\u3042\u308a\u307e\u305b\u3093\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#append-25","title":"append
\u306e\u4f7f\u7528\u306b\u3088\u308b\u4e88\u60f3\u5916\u306e\u526f\u4f5c\u7528 (#25)","text":"\u8981\u7d04 2\u3064\u306e\u7570\u306a\u308b\u95a2\u6570\u304c\u540c\u3058\u914d\u5217\u306b\u57fa\u3065\u304f\u30b9\u30e9\u30a4\u30b9\u3092\u4f7f\u7528\u3059\u308b\u5834\u5408\u306b\u3001copy \u307e\u305f\u306f\u5b8c\u5168\u30b9\u30e9\u30a4\u30b9\u5f0f\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u3067 append
\u306b\u3088\u308b\u885d\u7a81\u3092\u9632\u3050\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u305f\u3060\u3057\u3001\u5927\u304d\u306a\u30b9\u30e9\u30a4\u30b9\u3092\u7e2e\u5c0f\u3059\u308b\u5834\u5408\u3001\u30e1\u30e2\u30ea\u30ea\u30fc\u30af\u3092\u9632\u3050\u3053\u3068\u304c\u3067\u304d\u308b\u306e\u306f\u30b9\u30e9\u30a4\u30b9\u306e\u30b3\u30d4\u30fc\u3060\u3051\u3067\u3059\u3002
\u30b9\u30e9\u30a4\u30b9\u3092\u4f7f\u7528\u3059\u308b\u3068\u304d\u306f\u3001\u4e88\u60f3\u5916\u306e\u526f\u4f5c\u7528\u306b\u3064\u306a\u304c\u308b\u72b6\u6cc1\u306b\u76f4\u9762\u3059\u308b\u53ef\u80fd\u6027\u304c\u3042\u308b\u3053\u3068\u3092\u899a\u3048\u3066\u304a\u304f\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u7d50\u679c\u306e\u30b9\u30e9\u30a4\u30b9\u306e\u9577\u3055\u304c\u305d\u306e\u5bb9\u91cf\u3088\u308a\u5c0f\u3055\u3044\u5834\u5408\u3001\u8ffd\u52a0\u306b\u3088\u3063\u3066\u5143\u306e\u30b9\u30e9\u30a4\u30b9\u304c\u5909\u66f4\u3055\u308c\u308b\u53ef\u80fd\u6027\u304c\u3042\u308a\u307e\u3059\u3002\u8d77\u3053\u308a\u5f97\u308b\u526f\u4f5c\u7528\u306e\u7bc4\u56f2\u3092\u5236\u9650\u3057\u305f\u3044\u5834\u5408\u306f\u3001\u30b9\u30e9\u30a4\u30b9\u306e\u30b3\u30d4\u30fc\u307e\u305f\u306f\u5b8c\u5168\u30b9\u30e9\u30a4\u30b9\u5f0f\u3092\u4f7f\u7528\u3067\u304d\u307e\u3059\u3002\u3053\u308c\u306b\u3088\u308a\u3001\u30b3\u30d4\u30fc\u3092\u5b9f\u884c\u3067\u304d\u306a\u304f\u306a\u308a\u307e\u3059\u3002
\u88dc\u8db3s[low:high:max]
\uff08\u5b8c\u5168\u30b9\u30e9\u30a4\u30b9\u5f0f\uff09\u2015\u2015\u3053\u306e\u547d\u4ee4\u6587\u306f\u3001\u5bb9\u91cf\u304c max - low
\u306b\u7b49\u3057\u3044\u3053\u3068\u3092\u9664\u3051\u3070\u3001s[low:high]
\u3067\u4f5c\u6210\u3055\u308c\u305f\u30b9\u30e9\u30a4\u30b9\u3068\u540c\u69d8\u306e\u30b9\u30e9\u30a4\u30b9\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#26","title":"\u30b9\u30e9\u30a4\u30b9\u3068\u30e1\u30e2\u30ea\u30ea\u30fc\u30af (#26)","text":"\u8981\u7d04\u30dd\u30a4\u30f3\u30bf\u306e\u30b9\u30e9\u30a4\u30b9\u307e\u305f\u306f\u30dd\u30a4\u30f3\u30bf\u30d5\u30a3\u30fc\u30eb\u30c9\u3092\u6301\u3064\u69cb\u9020\u4f53\u3092\u64cd\u4f5c\u3059\u308b\u5834\u5408\u3001\u30b9\u30e9\u30a4\u30b9\u64cd\u4f5c\u306b\u3088\u3063\u3066\u9664\u5916\u3055\u308c\u305f\u8981\u7d20\u3092 nil \u3068\u3059\u308b\u3053\u3068\u3067\u30e1\u30e2\u30ea\u30ea\u30fc\u30af\u3092\u56de\u907f\u3067\u304d\u307e\u3059\u3002
"},{"location":"ja/#_3","title":"\u5bb9\u91cf\u6f0f\u308c","text":"\u5927\u304d\u306a\u30b9\u30e9\u30a4\u30b9\u307e\u305f\u306f\u914d\u5217\u3092\u30b9\u30e9\u30a4\u30b9\u3059\u308b\u3068\u3001\u30e1\u30e2\u30ea\u6d88\u8cbb\u304c\u9ad8\u304f\u306a\u308b\u53ef\u80fd\u6027\u304c\u3042\u308b\u3053\u3068\u306b\u6ce8\u610f\u3057\u3066\u304f\u3060\u3055\u3044\u3002\u6b8b\u308a\u306e\u30b9\u30da\u30fc\u30b9\u306f GC \u306b\u3088\u3063\u3066\u518d\u5229\u7528\u3055\u308c\u305a\u3001\u5c11\u6570\u306e\u8981\u7d20\u3057\u304b\u4f7f\u7528\u3057\u306a\u3044\u306b\u3082\u304b\u304b\u308f\u3089\u305a\u3001\u5927\u304d\u306a\u30d0\u30c3\u30ad\u30f3\u30b0\u914d\u5217\u304c\u4fdd\u6301\u3055\u308c\u307e\u3059\u3002\u30b9\u30e9\u30a4\u30b9\u306e\u30b3\u30d4\u30fc\u3092\u3059\u308b\u3053\u3068\u3067\u3001\u3053\u306e\u3088\u3046\u306a\u4e8b\u614b\u3092\u9632\u3050\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#_4","title":"\u30b9\u30e9\u30a4\u30b9\u3068\u30dd\u30a4\u30f3\u30bf","text":"\u30dd\u30a4\u30f3\u30bf\u307e\u305f\u306f\u30dd\u30a4\u30f3\u30bf\u30d5\u30a3\u30fc\u30eb\u30c9\u3092\u542b\u3080\u69cb\u9020\u4f53\u3092\u4f7f\u7528\u3057\u3066\u30b9\u30e9\u30a4\u30b9\u64cd\u4f5c\u3092\u3059\u308b\u5834\u5408\u3001GC \u304c\u3053\u308c\u3089\u306e\u8981\u7d20\u3092\u518d\u5229\u7528\u3057\u306a\u3044\u3053\u3068\u3092\u77e5\u3063\u3066\u304a\u304f\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u305d\u306e\u5834\u5408\u306e\u9078\u629e\u80a2\u306f\u3001\u30b3\u30d4\u30fc\u3092\u5b9f\u884c\u3059\u308b\u304b\u3001\u6b8b\u308a\u306e\u8981\u7d20\u307e\u305f\u306f\u305d\u306e\u30d5\u30a3\u30fc\u30eb\u30c9\u3092\u660e\u793a\u7684\u306b nil
\u3068\u3059\u308b\u3053\u3068\u3067\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#27","title":"\u975e\u52b9\u7387\u306a\u30de\u30c3\u30d7\u306e\u521d\u671f\u5316 (#27)","text":"\u8981\u7d04\u30de\u30c3\u30d7\u3092\u4f5c\u6210\u3059\u308b\u3068\u304d\u3001\u305d\u306e\u9577\u3055\u304c\u3059\u3067\u306b\u308f\u304b\u3063\u3066\u3044\u308b\u5834\u5408\u306f\u3001\u6307\u5b9a\u3055\u308c\u305f\u9577\u3055\u3067\u521d\u671f\u5316\u3057\u307e\u3059\u3002\u3053\u308c\u306b\u3088\u308a\u3001\u5272\u308a\u5f53\u3066\u306e\u6570\u304c\u6e1b\u308a\u3001\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u304c\u5411\u4e0a\u3057\u307e\u3059\u3002
\u30de\u30c3\u30d7\u306f\u3001\u30ad\u30fc\u30fb\u5024\u30da\u30a2\u306e\u9806\u5e8f\u306a\u3057\u30b3\u30ec\u30af\u30b7\u30e7\u30f3\u3092\u63d0\u4f9b\u3057\u307e\u3059\u3002\u306a\u304a\u3001\u305d\u308c\u305e\u308c\u306e\u30da\u30a2\u306f\u56fa\u6709\u306e\u30ad\u30fc\u3092\u6301\u3061\u307e\u3059\u3002Go\u8a00\u8a9e\u3067\u306f\u3001\u30de\u30c3\u30d7\u306f\u30cf\u30c3\u30b7\u30e5\u30c6\u30fc\u30d6\u30eb\u30c7\u30fc\u30bf\u69cb\u9020\u306b\u57fa\u3065\u3044\u3066\u3044\u307e\u3059\u3002\u5185\u90e8\u7684\u306b\u306f\u3001\u30cf\u30c3\u30b7\u30e5\u30c6\u30fc\u30d6\u30eb\u306f\u30d0\u30b1\u30c3\u30c8\u306e\u914d\u5217\u3067\u3042\u308a\u3001\u5404\u30d0\u30b1\u30c3\u30c8\u306f\u30ad\u30fc\u30fb\u5024\u30da\u30a2\u306e\u914d\u5217\u3078\u306e\u30dd\u30a4\u30f3\u30bf\u3067\u3059\u3002
\u30de\u30c3\u30d7\u306b\u542b\u307e\u308c\u308b\u8981\u7d20\u306e\u6570\u304c\u4e8b\u524d\u306b\u308f\u304b\u3063\u3066\u3044\u308b\u5834\u5408\u306f\u3001\u305d\u306e\u521d\u671f\u30b5\u30a4\u30ba\u3092\u6307\u5b9a\u3057\u3066\u4f5c\u6210\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u30de\u30c3\u30d7\u306e\u5897\u5927\u306f\u3001\u5341\u5206\u306a\u30b9\u30da\u30fc\u30b9\u3092\u518d\u5272\u308a\u5f53\u3066\u3057\u3001\u3059\u3079\u3066\u306e\u8981\u7d20\u306e\u30d0\u30e9\u30f3\u30b9\u3092\u518d\u8abf\u6574\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u305f\u3081\u3001\u8a08\u7b97\u91cf\u304c\u975e\u5e38\u306b\u591a\u304f\u306a\u308a\u307e\u3059\u304c\u3001\u3053\u308c\u306b\u3088\u308a\u305d\u308c\u3092\u56de\u907f\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#28","title":"\u30de\u30c3\u30d7\u3068\u30e1\u30e2\u30ea\u30ea\u30fc\u30af (#28)","text":"\u8981\u7d04\u30de\u30c3\u30d7\u306f\u30e1\u30e2\u30ea\u5185\u3067\u5e38\u306b\u5897\u5927\u3059\u308b\u53ef\u80fd\u6027\u304c\u3042\u308a\u307e\u3059\u304c\u3001\u7e2e\u5c0f\u3059\u308b\u3053\u3068\u306f\u3042\u308a\u307e\u305b\u3093\u3002\u3057\u305f\u304c\u3063\u3066\u3001\u30e1\u30e2\u30ea\u306e\u554f\u984c\u304c\u767a\u751f\u3059\u308b\u5834\u5408\u306f\u3001\u30de\u30c3\u30d7\u3092\u5f37\u5236\u7684\u306b\u518d\u751f\u6210\u3057\u305f\u308a\u3001\u30dd\u30a4\u30f3\u30bf\u3092\u4f7f\u7528\u3057\u305f\u308a\u3059\u308b\u306a\u3069\u3001\u3055\u307e\u3056\u307e\u306a\u624b\u6bb5\u3092\u8a66\u3059\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002
\u30bb\u30af\u30b7\u30e7\u30f3\u5168\u6587\u306f\u3053\u3061\u3089\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#29","title":"\u8aa4\u3063\u305f\u65b9\u6cd5\u306b\u3088\u308b\u5024\u306e\u6bd4\u8f03 (#29)","text":"\u8981\u7d04Go\u8a00\u8a9e\u3067\u578b\u3092\u6bd4\u8f03\u3059\u200b\u200b\u308b\u306b\u306f\u30012 \u3064\u306e\u578b\u304c\u6bd4\u8f03\u53ef\u80fd\u306a\u3089\u3070\u3001== \u6f14\u7b97\u5b50\u3068 != \u6f14\u7b97\u5b50\u3092\u4f7f\u7528\u3067\u304d\u307e\u3059\u3002\u771f\u507d\u5024\u3001\u6570\u5024\u3001\u6587\u5b57\u5217\u3001\u30dd\u30a4\u30f3\u30bf\u3001\u30c1\u30e3\u30cd\u30eb\u3001\u304a\u3088\u3073\u69cb\u9020\u4f53\u304c\u5b8c\u5168\u306b\u6bd4\u8f03\u53ef\u80fd\u306a\u578b\u3067\u69cb\u6210\u3055\u308c\u3066\u3044\u307e\u3059\u3002\u305d\u308c\u4ee5\u5916\u306f\u3001 reflect.DeepEqual
\u3092\u4f7f\u7528\u3057\u3066\u30ea\u30d5\u30ec\u30af\u30b7\u30e7\u30f3\u306e\u4ee3\u511f\u3092\u652f\u6255\u3046\u304b\u3001\u72ec\u81ea\u306e\u5b9f\u88c5\u3068\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002
\u52b9\u679c\u7684\u306b\u6bd4\u8f03\u3059\u308b\u306b\u306f\u3001 ==
\u3068 !=
\u306e\u4f7f\u7528\u65b9\u6cd5\u3092\u7406\u89e3\u3059\u308b\u3053\u3068\u304c\u4e0d\u53ef\u6b20\u3067\u3059\u3002\u3053\u308c\u3089\u306e\u6f14\u7b97\u5b50\u306f\u3001\u6bd4\u8f03\u53ef\u80fd\u306a\u88ab\u6f14\u7b97\u5b50\u3067\u4f7f\u7528\u3067\u304d\u307e\u3059\u3002
?
\u3001 >=
\u3001 <
\u3001\u304a\u3088\u3073 >
\u6f14\u7b97\u5b50\u3092\u6570\u5024\u578b\u3067\u4f7f\u7528\u3057\u3066\u5024\u3092\u6bd4\u8f03\u3057\u305f\u308a\u3001\u6587\u5b57\u5217\u3067\u5b57\u53e5\u9806\u5e8f\u3092\u6bd4\u8f03\u3057\u305f\u308a\u3059\u308b\u3053\u3068\u3082\u3067\u304d\u307e\u3059\u3002
\u88ab\u6f14\u7b97\u5b50\u304c\u6bd4\u8f03\u3067\u304d\u306a\u3044\u5834\u5408\uff08\u30b9\u30e9\u30a4\u30b9\u3068\u30de\u30c3\u30d7\u306a\u3069\uff09\u3001\u30ea\u30d5\u30ec\u30af\u30b7\u30e7\u30f3\u306a\u3069\u306e\u4ed6\u306e\u65b9\u6cd5\u3092\u5229\u7528\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u30ea\u30d5\u30ec\u30af\u30b7\u30e7\u30f3\u306f\u30e1\u30bf\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u306e\u4e00\u7a2e\u3067\u3042\u308a\u3001\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u304c\u305d\u306e\u69cb\u9020\u3068\u52d5\u4f5c\u3092\u5185\u7701\u3057\u3066\u5909\u66f4\u3059\u308b\u6a5f\u80fd\u3092\u6307\u3057\u307e\u3059\u3002\u305f\u3068\u3048\u3070\u3001Go\u8a00\u8a9e\u3067\u306f reflect.DeepEqual
\u3092\u4f7f\u7528\u3067\u304d\u307e\u3059\u3002\u3053\u306e\u95a2\u6570\u306f\u30012\u3064\u306e\u5024\u3092\u518d\u5e30\u7684\u306b\u8abf\u3079\u308b\u3053\u3068\u306b\u3088\u3063\u3066\u30012\u3064\u306e\u8981\u7d20\u304c\u5b8c\u5168\u306b\u7b49\u3057\u3044\u304b\u3069\u3046\u304b\u3092\u5831\u544a\u3057\u307e\u3059\u3002\u53d7\u3051\u5165\u308c\u3089\u308c\u308b\u8981\u7d20\u306f\u3001\u57fa\u672c\u578b\u306b\u52a0\u3048\u3066\u3001\u914d\u5217\u3001\u69cb\u9020\u4f53\u3001\u30b9\u30e9\u30a4\u30b9\u3001\u30de\u30c3\u30d7\u3001\u30dd\u30a4\u30f3\u30bf\u3001\u30a4\u30f3\u30bf\u30d5\u30a7\u30fc\u30b9\u3001\u95a2\u6570\u3067\u3059\u3002\u3057\u304b\u3057\u3001\u6700\u5927\u306e\u843d\u3068\u3057\u7a74\u306f\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u4e0a\u306e\u30da\u30ca\u30eb\u30c6\u30a3\u3067\u3059\u3002
\u5b9f\u884c\u6642\u306e\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u304c\u91cd\u8981\u306a\u5834\u5408\u306f\u3001\u72ec\u81ea\u306e\u30e1\u30bd\u30c3\u30c9\u3092\u5b9f\u88c5\u3059\u308b\u3053\u3068\u304c\u6700\u5584\u3068\u306a\u308b\u53ef\u80fd\u6027\u304c\u3042\u308a\u307e\u3059\u3002
\u8ffd\u8a18\uff1a\u6a19\u6e96\u30e9\u30a4\u30d6\u30e9\u30ea\u306b\u306f\u65e2\u306b\u6bd4\u8f03\u30e1\u30bd\u30c3\u30c9\u304c\u3044\u304f\u3064\u304b\u3042\u308b\u3053\u3068\u3092\u899a\u3048\u3066\u304a\u304f\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u305f\u3068\u3048\u3070\u3001\u6700\u9069\u5316\u3055\u308c\u305f bytes.Compare
\u95a2\u6570\u3092\u4f7f\u7528\u3057\u3066\u30012\u3064\u306e\u30d0\u30a4\u30c8\u30b9\u30e9\u30a4\u30b9\u3092\u6bd4\u8f03\u3067\u304d\u307e\u3059\u3002\u72ec\u81ea\u306e\u30e1\u30bd\u30c3\u30c9\u3092\u5b9f\u88c5\u3059\u308b\u524d\u306b\u3001\u8eca\u8f2a\u306e\u518d\u767a\u660e\u3092\u3057\u306a\u3044\u3088\u3046\u306b\u3057\u307e\u3057\u3087\u3046\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#_5","title":"\u5236\u5fa1\u69cb\u9020","text":""},{"location":"ja/#range-30","title":"\u8981\u7d20\u304crange
\u30eb\u30fc\u30d7\u5185\u3067\u30b3\u30d4\u30fc\u3055\u308c\u308b\u3053\u3068\u3092\u77e5\u3089\u306a\u3044 (#30)","text":"\u8981\u7d04 range
\u30eb\u30fc\u30d7\u5185\u306e value \u8981\u7d20\u306f\u30b3\u30d4\u30fc\u3067\u3059\u3002\u3057\u305f\u304c\u3063\u3066\u3001\u305f\u3068\u3048\u3070\u69cb\u9020\u4f53\u3092\u5909\u66f4\u3059\u308b\u306b\u306f\u3001\u305d\u306e\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u3092\u4ecb\u3057\u3066\u30a2\u30af\u30bb\u30b9\u3059\u308b\u304b\u3001\u5f93\u6765\u306e for
\u30eb\u30fc\u30d7\u3092\u4ecb\u3057\u3066\u30a2\u30af\u30bb\u30b9\u3057\u307e\u3057\u3087\u3046\uff08\u5909\u66f4\u3059\u308b\u8981\u7d20\u307e\u305f\u306f\u30d5\u30a3\u30fc\u30eb\u30c9\u304c\u30dd\u30a4\u30f3\u30bf\u3067\u3042\u308b\u5834\u5408\u3092\u9664\u304f\uff09\u3002
range \u30eb\u30fc\u30d7\u3092\u4f7f\u7528\u3059\u308b\u3068\u3001\u3055\u307e\u3056\u307e\u306a\u30c7\u30fc\u30bf\u69cb\u9020\u306b\u53cd\u5fa9\u51e6\u7406\u3092\u884c\u3046\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002
\u53e4\u5178\u7684\u306a for
\u30eb\u30fc\u30d7\u3068\u6bd4\u8f03\u3059\u308b\u3068\u3001range
\u30eb\u30fc\u30d7\u306f\u305d\u306e\u7c21\u6f54\u306a\u69cb\u6587\u306e\u304a\u304b\u3052\u3067\u3001\u3053\u308c\u3089\u306e\u30c7\u30fc\u30bf\u69cb\u9020\u306e\u3059\u3079\u3066\u306e\u8981\u7d20\u306b\u53cd\u5fa9\u51e6\u7406\u3092\u3059\u308b\u306e\u306b\u4fbf\u5229\u3067\u3059\u3002
\u305f\u3060\u3057\u3001range \u30eb\u30fc\u30d7\u5185\u306e\u5024\u8981\u7d20\u306f\u30b3\u30d4\u30fc\u3067\u3042\u308b\u3053\u3068\u3092\u899a\u3048\u3066\u304a\u304f\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u3057\u305f\u304c\u3063\u3066\u3001\u5024\u3092\u5909\u66f4\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u69cb\u9020\u4f53\u306e\u5834\u5408\u3001\u5909\u66f4\u3059\u308b\u5024\u307e\u305f\u306f\u30d5\u30a3\u30fc\u30eb\u30c9\u304c\u30dd\u30a4\u30f3\u30bf\u3067\u306a\u3044\u9650\u308a\u3001\u8981\u7d20\u81ea\u4f53\u3067\u306f\u306a\u304f\u30b3\u30d4\u30fc\u306e\u307f\u3092\u66f4\u65b0\u3057\u307e\u3059\u3002range \u30eb\u30fc\u30d7\u307e\u305f\u306f\u5f93\u6765\u306e for \u30eb\u30fc\u30d7\u3092\u4f7f\u7528\u3057\u3066\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u7d4c\u7531\u3067\u8981\u7d20\u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b\u3053\u3068\u304c\u63a8\u5968\u3055\u308c\u307e\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#range-31","title":"range
\u30eb\u30fc\u30d7\uff08\u30c1\u30e3\u30cd\u30eb\u3068\u914d\u5217\uff09\u3067\u306e\u5f15\u6570\u306e\u8a55\u4fa1\u65b9\u6cd5\u3092\u77e5\u3089\u306a\u3044 (#31)","text":"\u8981\u7d04 range
\u6f14\u7b97\u5b50\u306b\u6e21\u3055\u308c\u308b\u5f0f\u306f\u30eb\u30fc\u30d7\u306e\u958b\u59cb\u524d\u306b 1 \u56de\u3060\u3051\u8a55\u4fa1\u3055\u308c\u308b\u3053\u3068\u3092\u7406\u89e3\u3059\u308b\u3068\u3001\u30c1\u30e3\u30cd\u30eb\u307e\u305f\u306f\u30b9\u30e9\u30a4\u30b9\u306e\u53cd\u5fa9\u51e6\u7406\u306b\u304a\u3051\u308b\u975e\u52b9\u7387\u306a\u5272\u308a\u5f53\u3066\u306a\u3069\u306e\u3042\u308a\u304c\u3061\u306a\u9593\u9055\u3044\u3092\u56de\u907f\u3067\u304d\u307e\u3059\u3002
range \u30eb\u30fc\u30d7\u306f\u3001\uff08\u30bf\u30a4\u30d7\u306b\u95a2\u4fc2\u306a\u304f\uff09\u30b3\u30d4\u30fc\u3092\u5b9f\u884c\u3059\u308b\u3053\u3068\u306b\u3088\u308a\u3001\u30eb\u30fc\u30d7\u306e\u958b\u59cb\u524d\u306b\u3001\u6307\u5b9a\u3055\u308c\u305f\u5f0f\u3092 1 \u56de\u3060\u3051\u8a55\u4fa1\u3057\u307e\u3059\u3002\u305f\u3068\u3048\u3070\u3001\u8aa4\u3063\u305f\u8981\u7d20\u306b\u30a2\u30af\u30bb\u30b9\u3057\u3066\u3057\u307e\u3046\u3001\u3068\u3044\u3046\u3088\u3046\u306a\u3042\u308a\u304c\u3061\u306a\u9593\u9055\u3044\u3092\u907f\u3051\u308b\u305f\u3081\u306b\u3001\u3053\u306e\u52d5\u4f5c\u3092\u899a\u3048\u3066\u304a\u304f\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u305f\u3068\u3048\u3070
a := [3]int{0, 1, 2}\nfor i, v := range a {\n a[2] = 10\n if i == 2 {\n fmt.Println(v)\n }\n}\n
\u3053\u306e\u30b3\u30fc\u30c9\u306f\u3001\u6700\u5f8c\u306e\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u3092 10 \u306b\u66f4\u65b0\u3057\u307e\u3059\u3002\u3057\u304b\u3057\u3001\u3053\u306e\u30b3\u30fc\u30c9\u3092\u5b9f\u884c\u3059\u308b\u3068\u300110 \u306f\u51fa\u529b\u3055\u308c\u307e\u305b\u3093\u3002 2 \u304c\u51fa\u529b\u3055\u308c\u307e\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#range-32","title":"range
\u30eb\u30fc\u30d7\u5185\u306b\u304a\u3051\u308b\u30dd\u30a4\u30f3\u30bf\u8981\u7d20\u306e\u4f7f\u7528\u304c\u53ca\u307c\u3059\u5f71\u97ff\u3092\u5206\u304b\u3063\u3066\u3044\u306a\u3044 (#32)","text":"\u8981\u7d04 \u30ed\u30fc\u30ab\u30eb\u5909\u6570\u3092\u4f7f\u7528\u3059\u308b\u304b\u3001\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u3092\u4f7f\u7528\u3057\u3066\u8981\u7d20\u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b\u3068\u3001\u30eb\u30fc\u30d7\u5185\u3067\u30dd\u30a4\u30f3\u30bf\u3092\u30b3\u30d4\u30fc\u3059\u308b\u969b\u306e\u9593\u9055\u3044\u3092\u9632\u3050\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002
range
\u30eb\u30fc\u30d7\u3092\u4f7f\u7528\u3057\u3066\u30c7\u30fc\u30bf\u69cb\u9020\u306b\u53cd\u5fa9\u51e6\u7406\u3092\u65bd\u3059\u5834\u5408\u3001\u3059\u3079\u3066\u306e\u5024\u304c\u5358\u4e00\u306e\u4e00\u610f\u306e\u30a2\u30c9\u30ec\u30b9\u3092\u6301\u3064\u4e00\u610f\u306e\u5909\u6570\u306b\u5272\u308a\u5f53\u3066\u3089\u308c\u308b\u3053\u3068\u3092\u601d\u3044\u51fa\u3057\u3066\u304f\u3060\u3055\u3044\u3002\u3086\u3048\u306b\u3001\u5404\u53cd\u5fa9\u51e6\u7406\u4e2d\u306b\u3053\u306e\u5909\u6570\u3092\u53c2\u7167\u3059\u308b\u30dd\u30a4\u30f3\u30bf\u3092\u4fdd\u5b58\u3059\u308b\u3068\u3001\u540c\u3058\u8981\u7d20\u3001\u3064\u307e\u308a\u6700\u65b0\u306e\u8981\u7d20\u3092\u53c2\u7167\u3059\u308b\u540c\u3058\u30dd\u30a4\u30f3\u30bf\u3092\u4fdd\u5b58\u3059\u308b\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002\u3053\u306e\u554f\u984c\u306f\u3001\u30eb\u30fc\u30d7\u306e\u30b9\u30b3\u30fc\u30d7\u5185\u306b\u30ed\u30fc\u30ab\u30eb\u5909\u6570\u3092\u5f37\u5236\u7684\u306b\u4f5c\u6210\u3059\u308b\u304b\u3001\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u3092\u4ecb\u3057\u3066\u30b9\u30e9\u30a4\u30b9\u8981\u7d20\u3092\u53c2\u7167\u3059\u308b\u30dd\u30a4\u30f3\u30bf\u3092\u4f5c\u6210\u3059\u308b\u3053\u3068\u3067\u89e3\u6c7a\u3067\u304d\u307e\u3059\u3002\u3069\u3061\u3089\u306e\u89e3\u6c7a\u7b56\u3067\u3082\u554f\u984c\u3042\u308a\u307e\u305b\u3093\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#33","title":"\u30de\u30c3\u30d7\u306e\u53cd\u5fa9\u51e6\u7406\u4e2d\u306b\u8aa4\u3063\u305f\u4eee\u5b9a\u3092\u3059\u308b\uff08\u53cd\u5fa9\u51e6\u7406\u4e2d\u306e\u9806\u5e8f\u4ed8\u3051\u3068\u30de\u30c3\u30d7\u306e\u633f\u5165\uff09 (#33)","text":"\u8981\u7d04\u30de\u30c3\u30d7\u3092\u4f7f\u7528\u3059\u308b\u3068\u304d\u306b\u4e88\u6e2c\u53ef\u80fd\u306a\u51fa\u529b\u3092\u4fdd\u8a3c\u3059\u308b\u306b\u306f\u3001\u30de\u30c3\u30d7\u306e\u30c7\u30fc\u30bf\u69cb\u9020\u304c\u6b21\u306e\u3068\u304a\u308a\u3067\u3042\u308b\u3053\u3068\u306b\u6ce8\u610f\u3057\u3066\u304f\u3060\u3055\u3044\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#break-34","title":"break
\u6587\u304c\u3069\u306e\u3088\u3046\u306b\u6a5f\u80fd\u3059\u308b\u304b\u3092\u5206\u304b\u3063\u3066\u3044\u306a\u3044 (#34)","text":"\u8981\u7d04 \u30e9\u30d9\u30eb\u3068 break
\u307e\u305f\u306f continue
\u306e\u4f75\u7528\u306f\u3001\u7279\u5b9a\u306e\u547d\u4ee4\u6587\u3092\u5f37\u5236\u7684\u306b\u4e2d\u65ad\u3057\u307e\u3059\u3002\u3053\u308c\u306f\u3001\u30eb\u30fc\u30d7\u5185\u306e switch
\u307e\u305f\u306f select
\u6587\u3067\u5f79\u7acb\u3061\u307e\u3059\u3002
\u901a\u5e38\u3001break \u6587\u306f\u30eb\u30fc\u30d7\u306e\u5b9f\u884c\u3092\u7d42\u4e86\u3059\u308b\u305f\u3081\u306b\u4f7f\u7528\u3055\u308c\u307e\u3059\u3002\u30eb\u30fc\u30d7\u304c switch \u307e\u305f\u306f select \u3068\u7d44\u307f\u5408\u308f\u305b\u3066\u4f7f\u7528\u200b\u200b\u3055\u308c\u308b\u5834\u5408\u3001\u76ee\u7684\u306e\u547d\u4ee4\u6587\u3067\u306f\u306a\u3044\u306e\u306b\u4e2d\u65ad\u3055\u305b\u3066\u3057\u307e\u3046\u3001\u3068\u3044\u3046\u30df\u30b9\u3092\u3059\u308b\u3053\u3068\u304c\u958b\u767a\u8005\u306b\u306f\u3088\u304f\u3042\u308a\u307e\u3059\u3002\u305f\u3068\u3048\u3070
for i := 0; i < 5; i++ {\n fmt.Printf(\"%d \", i)\n\n switch i {\n default:\n case 2:\n break\n }\n}\n
break \u6587\u306f for
\u30eb\u30fc\u30d7\u3092\u7d42\u4e86\u3055\u305b\u308b\u306e\u3067\u306f\u306a\u304f\u3001\u4ee3\u308f\u308a\u306b switch
\u6587\u3092\u7d42\u4e86\u3055\u305b\u307e\u3059\u3002\u3057\u305f\u304c\u3063\u3066\u3001\u3053\u306e\u30b3\u30fc\u30c9\u306f 0 \u304b\u3089 2 \u307e\u3067\u3092\u53cd\u5fa9\u3059\u308b\u4ee3\u308f\u308a\u306b\u30010 \u304b\u3089 4 \u307e\u3067\u3092\u53cd\u5fa9\u3057\u307e\u3059\uff080 1 2 3 4
\uff09\u3002
\u899a\u3048\u3066\u304a\u304f\u3079\u304d\u91cd\u8981\u306a\u30eb\u30fc\u30eb\u306e1\u3064\u306f\u3001 break
\u6587\u306f\u6700\u3082\u5185\u5074\u306e for
\u3001switch
\u3001\u307e\u305f\u306f select
\u6587\u306e\u5b9f\u884c\u3092\u7d42\u4e86\u3059\u308b\u3068\u3044\u3046\u3053\u3068\u3067\u3059\u3002\u524d\u306e\u4f8b\u3067\u306f\u3001switch
\u6587\u3092\u7d42\u4e86\u3057\u307e\u3059\u3002
switch
\u6587\u306e\u4ee3\u308f\u308a\u306b\u30eb\u30fc\u30d7\u3092\u4e2d\u65ad\u3059\u308b\u6700\u3082\u6163\u7528\u7684\u306a\u65b9\u6cd5\u306f\u30e9\u30d9\u30eb\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u3067\u3059\u3002
loop:\n for i := 0; i < 5; i++ {\n fmt.Printf(\"%d \", i)\n\n switch i {\n default:\n case 2:\n break loop\n }\n }\n
\u3053\u3053\u3067\u306f\u3001loop
\u30e9\u30d9\u30eb\u3092 for
\u30eb\u30fc\u30d7\u306b\u95a2\u9023\u4ed8\u3051\u307e\u3059\u3002 \u6b21\u306b\u3001break
\u6587\u306b loop
\u30e9\u30d9\u30eb\u3092\u6307\u5b9a\u3059\u308b\u306e\u3067\u3001switch \u3067\u306f\u306a\u304f loop \u304c\u4e2d\u65ad\u3055\u308c\u307e\u3059\u3002\u3088\u3063\u3066\u3001\u3053\u306e\u65b0\u3057\u3044\u30d0\u30fc\u30b8\u30e7\u30f3\u306f\u4e88\u60f3\u3069\u304a\u308a 0 1 2
\u3092\u51fa\u529b\u3057\u307e\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#defer-35","title":"\u30eb\u30fc\u30d7\u5185\u3067defer
\u3092\u4f7f\u7528\u3059\u308b (#35)","text":"\u8981\u7d04 \u95a2\u6570\u5185\u306e\u30eb\u30fc\u30d7\u30ed\u30b8\u30c3\u30af\u306e\u62bd\u51fa\u306f\u3001\u5404\u53cd\u5fa9\u306e\u6700\u5f8c\u3067\u306e defer
\u6587\u306e\u5b9f\u884c\u306b\u3064\u306a\u304c\u308a\u307e\u3059\u3002
defer
\u6587\u306f\u3001\u4e0a\u4f4d\u30d6\u30ed\u30c3\u30af\u306e\u95a2\u6570\u304c\u623b\u308b\u307e\u3067\u547c\u3073\u51fa\u3057\u306e\u5b9f\u884c\u3092\u9045\u3089\u305b\u307e\u3059\u3002\u3053\u308c\u306f\u4e3b\u306b\u5b9a\u578b\u30b3\u30fc\u30c9\u3092\u524a\u6e1b\u3059\u308b\u305f\u3081\u306b\u4f7f\u7528\u3055\u308c\u307e\u3059\u3002\u305f\u3068\u3048\u3070\u3001\u30ea\u30bd\u30fc\u30b9\u3092\u6700\u7d42\u7684\u306b\u9589\u3058\u308b\u5fc5\u8981\u304c\u3042\u308b\u5834\u5408\u306f\u3001defer
\u3092\u4f7f\u7528\u3057\u3066\u3001return
\u3092\u5b9f\u884c\u3059\u308b\u524d\u306b\u30af\u30ed\u30fc\u30b8\u30e3\u547c\u3073\u51fa\u3057\u3092\u7e70\u308a\u8fd4\u3059\u3053\u3068\u3092\u907f\u3051\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002
defer
\u3067\u3088\u304f\u3042\u308b\u30df\u30b9\u306e1\u3064\u306f\u3001\u4e0a\u4f4d\u30d6\u30ed\u30c3\u30af \u306e\u95a2\u6570\u304c\u623b\u3063\u305f\u3068\u304d\u306b\u95a2\u6570\u547c\u3073\u51fa\u3057\u304c\u30b9\u30b1\u30b8\u30e5\u30fc\u30eb\u3055\u308c\u308b\u3053\u3068\u3092\u5fd8\u308c\u308b\u3053\u3068\u3067\u3059\u3002\u305f\u3068\u3048\u3070
func readFiles(ch <-chan string) error {\n for path := range ch {\n file, err := os.Open(path)\n if err != nil {\n return err\n }\n\n defer file.Close()\n\n // \u30d5\u30a1\u30a4\u30eb\u306e\u51e6\u7406\u3092\u3059\u308b\n }\n return nil\n}\n
defer
\u547c\u3073\u51fa\u3057\u306f\u3001\u5404\u30eb\u30fc\u30d7\u53cd\u5fa9\u4e2d\u3067\u306f\u306a\u304f\u3001readFiles
\u95a2\u6570\u304c\u8fd4\u3055\u308c\u305f\u3068\u304d\u306b\u5b9f\u884c\u3055\u308c\u307e\u3059\u3002 readFiles
\u304c\u8fd4\u3089\u306a\u3044\u5834\u5408\u3001\u30d5\u30a1\u30a4\u30eb\u8a18\u8ff0\u5b50\u306f\u6c38\u4e45\u306b\u958b\u3044\u305f\u307e\u307e\u306b\u306a\u308a\u3001\u30ea\u30fc\u30af\u304c\u767a\u751f\u3057\u307e\u3059\u3002
\u3053\u306e\u554f\u984c\u3092\u89e3\u6c7a\u3059\u308b\u305f\u3081\u306e\u4e00\u822c\u7684\u306a\u624b\u6bb5\u306e1\u3064\u306f\u3001 defer
\u306e\u5f8c\u306b\u3001\u5404\u53cd\u5fa9\u4e2d\u306b\u547c\u3073\u51fa\u3055\u308c\u308b\u4e0a\u4f4d\u30d6\u30ed\u30c3\u30af\u306e\u95a2\u6570\u3092\u4f5c\u6210\u3059\u308b\u3053\u3068\u3067\u3059\u3002
func readFiles(ch <-chan string) error {\n for path := range ch {\n if err := readFile(path); err != nil {\n return err\n }\n }\n return nil\n}\n\nfunc readFile(path string) error {\n file, err := os.Open(path)\n if err != nil {\n return err\n }\n\n defer file.Close()\n\n // \u30d5\u30a1\u30a4\u30eb\u306e\u51e6\u7406\u3092\u3059\u308b\n return nil\n}\n
\u5225\u306e\u89e3\u6c7a\u7b56\u306f\u3001readFile
\u95a2\u6570\u3092\u30af\u30ed\u30fc\u30b8\u30e3\u306b\u3059\u308b\u3053\u3068\u3067\u3059\u304c\u3001\u672c\u8cea\u7684\u306b\u306f\u540c\u3058\u3067\u3059\u3002\u5225\u306e\u4e0a\u4f4d\u30d6\u30ed\u30c3\u30af\u306e\u95a2\u6570\u3092\u8ffd\u52a0\u3057\u3066\u3001\u5404\u53cd\u5fa9\u4e2d\u306b defer
\u547c\u3073\u51fa\u3057\u3092\u5b9f\u884c\u3057\u307e\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#_6","title":"\u6587\u5b57\u5217","text":""},{"location":"ja/#36","title":"\u30eb\u30fc\u30f3\u3092\u7406\u89e3\u3057\u3066\u3044\u306a\u3044 (#36)","text":"\u8981\u7d04\u30eb\u30fc\u30f3\u304c Unicode \u30b3\u30fc\u30c9\u30dd\u30a4\u30f3\u30c8\u306e\u6982\u5ff5\u306b\u5bfe\u5fdc\u3057\u3001\u8907\u6570\u306e\u30d0\u30a4\u30c8\u3067\u69cb\u6210\u3055\u308c\u308b\u53ef\u80fd\u6027\u304c\u3042\u308b\u3053\u3068\u3092\u7406\u89e3\u3059\u308b\u3053\u3068\u306f\u3001 Go \u958b\u767a\u8005\u304c\u6587\u5b57\u5217\u3092\u6b63\u78ba\u306b\u64cd\u4f5c\u3059\u308b\u305f\u3081\u306b\u4e0d\u53ef\u6b20\u3067\u3059\u3002
Go\u8a00\u8a9e\u3067\u306f\u30eb\u30fc\u30f3\u304c\u3042\u3089\u3086\u308b\u5834\u6240\u306b\u4f7f\u7528\u3055\u308c\u308b\u305f\u3081\u3001\u6b21\u306e\u70b9\u3092\u7406\u89e3\u3059\u308b\u3053\u3068\u304c\u91cd\u8981\u3067\u3059\u3002
rune
\u306f Unicode \u30b3\u30fc\u30c9\u30dd\u30a4\u30f3\u30c8\u306e\u6982\u5ff5\u306b\u5bfe\u5fdc\u3057\u3001\u5358\u4e00\u306e\u5024\u3067\u8868\u3055\u308c\u308b\u30a2\u30a4\u30c6\u30e0\u3092\u610f\u5473\u3057\u307e\u3059\u3002len()
\u3092\u4f7f\u7528\u3059\u308b\u3068\u3001\u30eb\u30fc\u30f3\u6570\u3067\u306f\u306a\u304f\u30d0\u30a4\u30c8\u6570\u304c\u8fd4\u3055\u308c\u307e\u3059\u3002\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#37","title":"\u6587\u5b57\u5217\u306b\u5bfe\u3059\u308b\u4e0d\u6b63\u306a\u53cd\u5fa9\u51e6\u7406 (#37)","text":"\u8981\u7d04range
\u6f14\u7b97\u5b50\u3092\u4f7f\u7528\u3057\u3066\u6587\u5b57\u5217\u3092\u53cd\u5fa9\u51e6\u7406\u3059\u308b\u3068\u3001\u30eb\u30fc\u30f3\u306e\u30d0\u30a4\u30c8\u30b7\u30fc\u30b1\u30f3\u30b9\u306e\u958b\u59cb\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u306b\u5bfe\u5fdc\u3059\u308b\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u3092\u4f7f\u7528\u3057\u3066\u30eb\u30fc\u30f3\u304c\u53cd\u5fa9\u51e6\u7406\u3055\u308c\u307e\u3059\u3002\u7279\u5b9a\u306e\u30eb\u30fc\u30f3\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\uff08 3 \u756a\u76ee\u306e\u30eb\u30fc\u30f3\u306a\u3069\uff09\u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b\u306b\u306f\u3001\u6587\u5b57\u5217\u3092 []rune
\u306b\u5909\u63db\u3057\u307e\u3059\u3002
\u6587\u5b57\u5217\u306e\u53cd\u5fa9\u51e6\u7406\u306f\u3001\u958b\u767a\u8005\u306b\u3068\u3063\u3066\u4e00\u822c\u7684\u306a\u64cd\u4f5c\u3067\u3059\u3002\u304a\u305d\u3089\u304f\u3001\u6587\u5b57\u5217\u5185\u306e\u5404\u30eb\u30fc\u30f3\u306b\u5bfe\u3057\u3066\u64cd\u4f5c\u3092\u5b9f\u884c\u3059\u308b\u304b\u3001\u7279\u5b9a\u306e\u90e8\u5206\u6587\u5b57\u5217\u3092\u691c\u7d22\u3059\u308b\u72ec\u81ea\u306e\u95a2\u6570\u3092\u5b9f\u88c5\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u3067\u3057\u3087\u3046\u3002\u3069\u3061\u3089\u306e\u5834\u5408\u3082\u3001\u6587\u5b57\u5217\u306e\u7570\u306a\u308b\u30eb\u30fc\u30f3\u3092\u53cd\u5fa9\u51e6\u7406\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u3057\u304b\u3057\u3001\u53cd\u5fa9\u51e6\u7406\u304c\u3069\u306e\u3088\u3046\u306b\u6a5f\u80fd\u3059\u308b\u304b\u306b\u3064\u3044\u3066\u306f\u56f0\u60d1\u3057\u3084\u3059\u3044\u3067\u3059\u3002
\u6b21\u306e\u4f8b\u3092\u8003\u3048\u3066\u307f\u307e\u3057\u3087\u3046\u3002
s := \"h\u00eallo\"\nfor i := range s {\n fmt.Printf(\"position %d: %c\\n\", i, s[i])\n}\nfmt.Printf(\"len=%d\\n\", len(s))\n
position 0: h\nposition 1: \u00c3\nposition 3: l\nposition 4: l\nposition 5: o\nlen=6\n
\u6df7\u4e71\u3092\u62db\u304f\u53ef\u80fd\u6027\u306e\u3042\u308b 3 \u70b9\u3092\u53d6\u308a\u4e0a\u3052\u307e\u3057\u3087\u3046\u3002
\u7d50\u679c\u306e\u6700\u5f8c\u304b\u3089\u898b\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u3002len \u306f\u30eb\u30fc\u30f3\u6570\u3067\u306f\u306a\u304f\u3001\u6587\u5b57\u5217\u5185\u306e\u30d0\u30a4\u30c8\u6570\u3092\u8fd4\u3059\u3053\u3068\u306f\u3059\u3067\u306b\u8ff0\u3079\u307e\u3057\u305f\u3002\u6587\u5b57\u5217\u30ea\u30c6\u30e9\u30eb\u3092 s
\u306b\u5272\u308a\u5f53\u3066\u3066\u3044\u308b\u305f\u3081\u3001s
\u306f UTF-8 \u6587\u5b57\u5217\u3067\u3059\u3002\u4e00\u65b9\u3001\u7279\u6b8a\u6587\u5b57\u300c\u00ea\u300d\u306f 1 \u30d0\u30a4\u30c8\u3067\u30a8\u30f3\u30b3\u30fc\u30c9\u3055\u308c\u307e\u305b\u3093\u3002 2 \u30d0\u30a4\u30c8\u5fc5\u8981\u3067\u3059\u3002\u3057\u305f\u304c\u3063\u3066\u3001len(s)
\u3092\u547c\u3073\u51fa\u3059\u3068 6 \u304c\u8fd4\u3055\u308c\u307e\u3059\u3002
\u524d\u306e\u4f8b\u3067\u306f\u3001\u5404\u30eb\u30fc\u30f3\u3092\u53cd\u5fa9\u51e6\u7406\u3057\u3066\u3044\u306a\u3044\u3053\u3068\u3092\u7406\u89e3\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u4ee3\u308f\u308a\u306b\u3001\u30eb\u30fc\u30f3\u306e\u5404\u958b\u59cb\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u3092\u53cd\u5fa9\u51e6\u7406\u3057\u307e\u3059\u3002
s[i]
\u3092\u51fa\u529b\u3057\u3066\u3082 i \u756a\u76ee\u306e\u30eb\u30fc\u30f3\u306f\u51fa\u529b\u3055\u308c\u307e\u305b\u3093\u3002\u30a4\u30f3\u30c7\u30c3\u30af\u30b9 i
\u306e\u30d0\u30a4\u30c8\u306e UTF-8 \u8868\u73fe\u3092\u51fa\u529b\u3057\u307e\u3059\u3002\u3057\u305f\u304c\u3063\u3066\u3001 h\u00eallo
\u306e\u4ee3\u308f\u308a\u306b h\u00c3llo
\u3092\u51fa\u529b\u304c\u3055\u308c\u307e\u3059\u3002
\u3055\u307e\u3056\u307e\u306a\u30eb\u30fc\u30f3\u6587\u5b57\u3092\u3059\u3079\u3066\u51fa\u529b\u3057\u305f\u3044\u5834\u5408\u306f\u3001 range
\u6f14\u7b97\u5b50\u306e value \u8981\u7d20\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002
s := \"h\u00eallo\"\nfor i, r := range s {\n fmt.Printf(\"position %d: %c\\n\", i, r)\n}\n
\u307e\u305f\u306f\u3001\u6587\u5b57\u5217\u3092\u30eb\u30fc\u30f3\u306e\u30b9\u30e9\u30a4\u30b9\u306b\u5909\u63db\u3057\u3001\u305d\u308c\u3092\u53cd\u5fa9\u51e6\u7406\u3059\u308b\u3053\u3068\u3082\u3067\u304d\u307e\u3059\u3002
s := \"h\u00eallo\"\nrunes := []rune(s)\nfor i, r := range runes {\n fmt.Printf(\"position %d: %c\\n\", i, r)\n}\n
\u3053\u306e\u89e3\u6c7a\u7b56\u3067\u306f\u3001\u4ee5\u524d\u306e\u89e3\u6c7a\u7b56\u3068\u6bd4\u8f03\u3057\u3066\u5b9f\u884c\u6642\u306e\u30aa\u30fc\u30d0\u30fc\u30d8\u30c3\u30c9\u304c\u767a\u751f\u3059\u308b\u3053\u3068\u306b\u6ce8\u610f\u3057\u3066\u304f\u3060\u3055\u3044\u3002\u5b9f\u969b\u3001\u6587\u5b57\u5217\u3092\u30eb\u30fc\u30f3\u306e\u30b9\u30e9\u30a4\u30b9\u306b\u5909\u63db\u3059\u308b\u306b\u306f\u3001\u8ffd\u52a0\u306e\u30b9\u30e9\u30a4\u30b9\u3092\u5272\u308a\u5f53\u3066\u3001\u30d0\u30a4\u30c8\u3092\u30eb\u30fc\u30f3\u306b\u5909\u63db\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u6587\u5b57\u5217\u306e\u30d0\u30a4\u30c8\u6570\u3092 n \u3068\u3059\u308b\u3068\u3001\u6642\u9593\u8a08\u7b97\u91cf\u306f O(n) \u306b\u306a\u308a\u307e\u3059\u3002\u3057\u305f\u304c\u3063\u3066\u3001\u3059\u3079\u3066\u306e\u30eb\u30fc\u30f3\u3092\u53cd\u5fa9\u51e6\u7406\u3059\u308b\u5834\u5408\u306f\u3001\u6700\u521d\u306e\u89e3\u6c7a\u7b56\u3092\u4f7f\u7528\u3059\u308b\u3079\u304d\u3067\u3059\u3002
\u305f\u3060\u3057\u3001\u6700\u521d\u306e\u65b9\u6cd5\u3092\u4f7f\u7528\u3057\u3066\u6587\u5b57\u5217\u306e i \u756a\u76ee\u306e\u30eb\u30fc\u30f3\u306b\u30a2\u30af\u30bb\u30b9\u3057\u305f\u3044\u5834\u5408\u306f\u3001\u30eb\u30fc\u30f3\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u306b\u30a2\u30af\u30bb\u30b9\u3067\u304d\u307e\u305b\u3093\u3002\u4ee3\u308f\u308a\u306b\u3001\u30d0\u30a4\u30c8\u30b7\u30fc\u30b1\u30f3\u30b9\u5185\u306e\u30eb\u30fc\u30f3\u306e\u958b\u59cb\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u304c\u308f\u304b\u308a\u307e\u3059\u3002
s := \"h\u00eallo\"\nr := []rune(s)[4]\nfmt.Printf(\"%c\\n\", r) // o\n
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#trim-38","title":"trim \u95a2\u6570\u306e\u8aa4\u7528 (#38)","text":"\u8981\u7d04strings.TrimRight
\u30fb strings.TrimLeft
\u306f\u3001\u6307\u5b9a\u3055\u308c\u305f\u30bb\u30c3\u30c8\u306b\u542b\u307e\u308c\u308b\u3059\u3079\u3066\u306e\u672b\u5c3e\u30fb\u5148\u982d\u306e\u30eb\u30fc\u30f3\u3092\u524a\u9664\u3057\u307e\u3059\u304c\u3001 strings.TrimSuffix
\u30fb strings.TrimPrefix
\u306f\u3001\u6307\u5b9a\u3055\u308c\u305f\u63a5\u5c3e\u8f9e\u30fb\u63a5\u982d\u8f9e\u306e\u306a\u3044\u6587\u5b57\u5217\u3092\u8fd4\u3057\u307e\u3059\u3002
\u305f\u3068\u3048\u3070
fmt.Println(strings.TrimRight(\"123oxo\", \"xo\"))\n
\u306f 123 \u3092\u51fa\u529b\u3057\u307e\u3059
\u9006\u306b\u3001 strings.TrimLeft
\u306f\u3001\u30bb\u30c3\u30c8\u306b\u542b\u307e\u308c\u308b\u5148\u982d\u306e\u30eb\u30fc\u30f3\u3092\u3059\u3079\u3066\u524a\u9664\u3057\u307e\u3059\u3002
\u4e00\u65b9\u3001strings.TrimSuffix
\u30fb strings.TrimPrefix
\u306f\u3001\u6307\u5b9a\u3055\u308c\u305f\u672b\u5c3e\u306e\u63a5\u5c3e\u8f9e\u30fb\u63a5\u982d\u8f9e\u3092\u9664\u3044\u305f\u6587\u5b57\u5217\u3092\u8fd4\u3057\u307e\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#39","title":"\u6700\u9069\u5316\u304c\u4e0d\u5341\u5206\u306a\u6587\u5b57\u5217\u306e\u9023\u7d50 (#39)","text":"\u8981\u7d04\u6587\u5b57\u5217\u306e\u30ea\u30b9\u30c8\u306e\u9023\u7d50\u306f\u3001\u53cd\u5fa9\u3054\u3068\u306b\u65b0\u3057\u3044\u6587\u5b57\u5217\u304c\u5272\u308a\u5f53\u3066\u3089\u308c\u306a\u3044\u3088\u3046\u306b\u3001strings.Builder
\u3092\u4f7f\u7528\u3057\u3066\u884c\u3046\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002
+=
\u6f14\u7b97\u5b50\u3092\u7528\u3044\u3066\u30b9\u30e9\u30a4\u30b9\u306e\u3059\u3079\u3066\u306e\u6587\u5b57\u5217\u8981\u7d20\u3092\u9023\u7d50\u3059\u308b concat
\u95a2\u6570\u3092\u8003\u3048\u3066\u307f\u307e\u3057\u3087\u3046\u3002
func concat(values []string) string {\n s := \"\"\n for _, value := range values {\n s += value\n }\n return s\n}\n
\u5404\u53cd\u5fa9\u4e2d\u306b\u3001 +=
\u6f14\u7b97\u5b50\u306f s
\u3068 value \u6587\u5b57\u5217\u3092\u9023\u7d50\u3057\u307e\u3059\u3002\u4e00\u898b\u3059\u308b\u3068\u3001\u3053\u306e\u95a2\u6570\u306f\u9593\u9055\u3063\u3066\u3044\u306a\u3044\u3088\u3046\u306b\u898b\u3048\u308b\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002\u3057\u304b\u3057\u3001\u3053\u306e\u5b9f\u88c5\u306f\u3001\u6587\u5b57\u5217\u306e\u6838\u3068\u306a\u308b\u7279\u6027\u306e1\u3064\u3067\u3042\u308b\u4e0d\u5909\u6027\u3092\u5fd8\u308c\u3066\u3044\u307e\u3059\u3002\u3057\u305f\u304c\u3063\u3066\u3001\u5404\u53cd\u5fa9\u3067\u306f s
\u306f\u66f4\u65b0\u3055\u308c\u307e\u305b\u3093\u3002\u30e1\u30e2\u30ea\u5185\u306b\u65b0\u3057\u3044\u6587\u5b57\u5217\u3092\u518d\u5272\u308a\u5f53\u3066\u3059\u308b\u305f\u3081\u3001\u3053\u306e\u95a2\u6570\u306e\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u306b\u5927\u304d\u306a\u5f71\u97ff\u3092\u4e0e\u3048\u307e\u3059\u3002
\u5e78\u3044\u306a\u3053\u3068\u306b\u3001 strings.Builder
\u3092\u7528\u3044\u308b\u3053\u3068\u3067\u3001\u3053\u306e\u554f\u984c\u306b\u5bfe\u51e6\u3059\u308b\u89e3\u6c7a\u7b56\u304c\u3042\u308a\u307e\u3059\u3002
func concat(values []string) string {\n sb := strings.Builder{}\n for _, value := range values {\n _, _ = sb.WriteString(value)\n }\n return sb.String()\n}\n
\u5404\u53cd\u5fa9\u4e2d\u306b\u3001value \u306e\u5185\u5bb9\u3092\u5185\u90e8\u30d0\u30c3\u30d5\u30a1\u306b\u8ffd\u52a0\u3059\u308b WriteString
\u30e1\u30bd\u30c3\u30c9\u3092\u547c\u3073\u51fa\u3057\u3066\u7d50\u679c\u306e\u6587\u5b57\u5217\u3092\u69cb\u7bc9\u3057\u3001\u30e1\u30e2\u30ea\u306e\u30b3\u30d4\u30fc\u3092\u6700\u5c0f\u9650\u306b\u6291\u3048\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3057\u305f\u3002
WriteString
\u306f 2 \u756a\u76ee\u306e\u51fa\u529b\u3068\u3057\u3066\u30a8\u30e9\u30fc\u3092\u8fd4\u3057\u307e\u3059\u304c\u3001\u610f\u56f3\u7684\u306b\u7121\u8996\u3057\u307e\u3057\u3087\u3046\u3002\u5b9f\u969b\u3001\u3053\u306e\u30e1\u30bd\u30c3\u30c9\u306f nil \u30a8\u30e9\u30fc\u4ee5\u5916\u3092\u8fd4\u3059\u3053\u3068\u306f\u3042\u308a\u307e\u305b\u3093\u3002\u3067\u306f\u3001\u3053\u306e\u30e1\u30bd\u30c3\u30c9\u304c\u30b7\u30b0\u30cd\u30c1\u30e3\u306e\u4e00\u90e8\u3068\u3057\u3066\u30a8\u30e9\u30fc\u3092\u8fd4\u3059\u76ee\u7684\u306f\u4f55\u3067\u3057\u3087\u3046\u304b\u3002strings.Builder
\u306f io.StringWriter
\u30a4\u30f3\u30bf\u30d5\u30a7\u30fc\u30b9\u3092\u5b9f\u88c5\u3057\u3066\u304a\u308a\u3001\u3053\u308c\u306b\u306f WriteString(s string) (n int, err error)
\u3068\u3044\u30461\u3064\u306e\u30e1\u30bd\u30c3\u30c9\u304c\u542b\u307e\u308c\u3066\u3044\u307e\u3059\u3002\u3057\u305f\u304c\u3063\u3066\u3001\u3053\u306e\u30a4\u30f3\u30bf\u30d5\u30a7\u30fc\u30b9\u306b\u6e96\u62e0\u3059\u308b\u306b\u306f\u3001WriteString
\u306f\u30a8\u30e9\u30fc\u3092\u8fd4\u3055\u306a\u3051\u308c\u3070\u306a\u3089\u306a\u3044\u306e\u3067\u3059\u3002
\u5185\u90e8\u7684\u306b\u306f\u3001strings.Builder
\u306f\u30d0\u30a4\u30c8\u30b9\u30e9\u30a4\u30b9\u3092\u4fdd\u6301\u3057\u307e\u3059\u3002 WriteString
\u3092\u547c\u3073\u51fa\u3059\u305f\u3073\u306b\u3001\u3053\u306e\u30b9\u30e9\u30a4\u30b9\u306b\u8ffd\u52a0\u3059\u308b\u547c\u3073\u51fa\u3057\u304c\u884c\u308f\u308c\u307e\u3059\u3002\u3053\u308c\u306b\u306f2\u3064\u306e\u5f71\u97ff\u304c\u3042\u308a\u307e\u3059\u3002\u307e\u305a\u3001 append
\u306e\u547c\u3073\u51fa\u3057\u304c\u885d\u7a81\u72b6\u614b\u3092\u5f15\u304d\u8d77\u3053\u3059\u53ef\u80fd\u6027\u304c\u3042\u308b\u305f\u3081\u3001\u3053\u306e\u69cb\u9020\u4f53\u306f\u540c\u6642\u306b\u4f7f\u7528\u3055\u308c\u308b\u3079\u304d\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u30022\u756a\u76ee\u306e\u5f71\u97ff\u306f\u3001 \u975e\u52b9\u7387\u306a\u30b9\u30e9\u30a4\u30b9\u306e\u521d\u671f\u5316 (#21) \u3067\u898b\u305f\u3082\u306e\u3067\u3059\u3002\u30b9\u30e9\u30a4\u30b9\u306e\u5c06\u6765\u306e\u9577\u3055\u304c\u3059\u3067\u306b\u308f\u304b\u3063\u3066\u3044\u308b\u5834\u5408\u306f\u3001\u305d\u308c\u3092\u4e8b\u524d\u306b\u5272\u308a\u5f53\u3066\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u305d\u306e\u305f\u3081\u306b\u3001strings.Builder
\u306f\u5225\u306e n
\u30d0\u30a4\u30c8\u306e\u305f\u3081\u306e\u30b9\u30da\u30fc\u30b9\u3092\u4fdd\u8a3c\u3059\u308b\u30e1\u30bd\u30c3\u30c9 Grow(n int)
\u3092\u6301\u3063\u3066\u3044\u307e\u3059\u3002
func concat(values []string) string {\n total := 0\n for i := 0; i < len(values); i++ {\n total += len(values[i])\n }\n\n sb := strings.Builder{}\n sb.Grow(total) (2)\n for _, value := range values {\n _, _ = sb.WriteString(value)\n }\n return sb.String()\n}\n
\u30d9\u30f3\u30c1\u30de\u30fc\u30af\u3092\u5b9f\u884c\u3057\u3066 3 \u3064\u306e\u30d0\u30fc\u30b8\u30e7\u30f3\uff08 +=
\u3092\u4f7f\u7528\u3057\u305f V1 \u3001\u4e8b\u524d\u5272\u308a\u5f53\u3066\u306a\u3057\u3067 strings.Builder{}
\u3092\u4f7f\u7528\u3057\u305f V2 \u3001\u4e8b\u524d\u5272\u308a\u5f53\u3066\u3042\u308a\u306e strings.Builder{}
\u3092\u4f7f\u7528\u3057\u305f V3 \uff09\u3092\u6bd4\u8f03\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002\u5165\u529b\u30b9\u30e9\u30a4\u30b9\u306b\u306f 1,000 \u500b\u306e\u6587\u5b57\u5217\u304c\u542b\u307e\u308c\u3066\u304a\u308a\u3001\u5404\u6587\u5b57\u5217\u306b\u306f 1,000 \u30d0\u30a4\u30c8\u304c\u542b\u307e\u308c\u3066\u3044\u307e\u3059\u3002
BenchmarkConcatV1-4 16 72291485 ns/op\nBenchmarkConcatV2-4 1188 878962 ns/op\nBenchmarkConcatV3-4 5922 190340 ns/op\n
\u3054\u89a7\u306e\u3068\u304a\u308a\u3001\u6700\u65b0\u30d0\u30fc\u30b8\u30e7\u30f3\u304c\u6700\u3082\u52b9\u7387\u7684\u3067\u3001V1 \u3088\u308a 99% \u3001V2 \u3088\u308a 78% \u9ad8\u901f\u3067\u3059\u3002
strings.Builder
\u306f\u3001\u6587\u5b57\u5217\u306e\u30ea\u30b9\u30c8\u3092\u9023\u7d50\u3059\u308b\u305f\u3081\u306e\u89e3\u6c7a\u7b56\u3068\u3057\u3066\u63a8\u5968\u3055\u308c\u307e\u3059\u3002\u901a\u5e38\u3001\u3053\u308c\u306f\u30eb\u30fc\u30d7\u5185\u3067\u4f7f\u7528\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u3044\u304f\u3064\u304b\u306e\u6587\u5b57\u5217 \uff08\u540d\u524d\u3068\u59d3\u306a\u3069\uff09\u3092\u9023\u7d50\u3059\u308b\u3060\u3051\u306e\u5834\u5408\u3001 strings.Builder
\u306e\u4f7f\u7528\u306f\u3001 +=
\u6f14\u7b97\u5b50\u3084 fmt.Sprintf
\u3068\u6bd4\u3079\u3066\u53ef\u8aad\u6027\u304c\u4f4e\u304f\u306a\u308b\u304b\u3089\u3067\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#40","title":"\u7121\u99c4\u306a\u6587\u5b57\u5217\u5909\u63db (#40)","text":"\u8981\u7d04bytes
\u30d1\u30c3\u30b1\u30fc\u30b8\u306f strings
\u30d1\u30c3\u30b1\u30fc\u30b8\u3068\u540c\u3058\u64cd\u4f5c\u3092\u63d0\u4f9b\u3057\u3066\u304f\u308c\u308b\u3053\u3068\u3092\u899a\u3048\u3066\u304a\u304f\u3068\u3001\u4f59\u5206\u306a\u30d0\u30a4\u30c8\u30fb\u6587\u5b57\u5217\u5909\u63db\u3092\u907f\u3051\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002
\u6587\u5b57\u5217\u307e\u305f\u306f []byte
\u3092\u6271\u3046\u3053\u3068\u3092\u9078\u629e\u3059\u308b\u5834\u5408\u3001\u307b\u3068\u3093\u3069\u306e\u30d7\u30ed\u30b0\u30e9\u30de\u30fc\u306f\u5229\u4fbf\u6027\u306e\u305f\u3081\u306b\u6587\u5b57\u5217\u3092\u597d\u3080\u50be\u5411\u304c\u3042\u308a\u307e\u3059\u3002\u3057\u304b\u3057\u3001\u307b\u3068\u3093\u3069\u306e I/O \u306f\u5b9f\u969b\u306b\u306f []byte
\u3067\u884c\u308f\u308c\u307e\u3059\u3002\u305f\u3068\u3048\u3070\u3001io.Reader
\u3001io.Writer
\u3001\u304a\u3088\u3073 io.ReadAll
\u306f\u6587\u5b57\u5217\u3067\u306f\u306a\u304f []byte
\u3092\u51e6\u7406\u3057\u307e\u3059\u3002
\u6587\u5b57\u5217\u3068 []byte
\u306e\u3069\u3061\u3089\u3092\u6271\u3046\u3079\u304d\u304b\u8ff7\u3063\u305f\u3068\u304d\u3001[]byte
\u3092\u6271\u3046\u65b9\u304c\u5fc5\u305a\u3057\u3082\u9762\u5012\u3060\u3068\u3044\u3046\u308f\u3051\u3067\u306f\u306a\u3044\u3053\u3068\u3092\u601d\u3044\u51fa\u3057\u3066\u304f\u3060\u3055\u3044\u3002strings \u30d1\u30c3\u30b1\u30fc\u30b8\u304b\u3089\u30a8\u30af\u30b9\u30dd\u30fc\u30c8\u3055\u308c\u305f\u3059\u3079\u3066\u306e\u95a2\u6570\u306b\u306f\u3001bytes
\u30d1\u30c3\u30b1\u30fc\u30b8\u306b\u4ee3\u66ff\u6a5f\u80fd\u304c\u3042\u308a\u307e\u3059\u3002 Split
\u3001Count
\u3001Contains
\u3001Index
\u306a\u3069\u3067\u3059\u3002\u3057\u305f\u304c\u3063\u3066\u3001I/O \u3092\u5b9f\u884c\u3057\u3066\u3044\u308b\u304b\u3069\u3046\u304b\u306b\u95a2\u4fc2\u306a\u304f\u3001\u6587\u5b57\u5217\u306e\u4ee3\u308f\u308a\u306b\u30d0\u30a4\u30c8\u3092\u4f7f\u7528\u3057\u3066\u30ef\u30fc\u30af\u30d5\u30ed\u30fc\u5168\u4f53\u3092\u5b9f\u88c5\u3067\u304d\u3001\u8ffd\u52a0\u306e\u5909\u63db\u30b3\u30b9\u30c8\u3092\u56de\u907f\u3067\u304d\u308b\u304b\u3069\u3046\u304b\u3092\u6700\u521d\u306b\u78ba\u8a8d\u3057\u307e\u3057\u3087\u3046\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#41","title":"\u90e8\u5206\u6587\u5b57\u5217\u3068\u30e1\u30e2\u30ea\u30ea\u30fc\u30af (#41)","text":"\u8981\u7d04\u90e8\u5206\u6587\u5b57\u5217\u306e\u4ee3\u308f\u308a\u306b\u30b3\u30d4\u30fc\u3092\u4f7f\u7528\u3059\u308b\u3068\u3001\u90e8\u5206\u6587\u5b57\u5217\u64cd\u4f5c\u306b\u3088\u3063\u3066\u8fd4\u3055\u308c\u308b\u6587\u5b57\u5217\u304c\u540c\u3058\u30d0\u30a4\u30c8\u914d\u5217\u306b\u3088\u3063\u3066\u30b5\u30dd\u30fc\u30c8\u3055\u308c\u308b\u305f\u3081\u3001\u30e1\u30e2\u30ea\u30ea\u30fc\u30af\u3092\u9632\u3050\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002
\u30b9\u30e9\u30a4\u30b9\u3068\u30e1\u30e2\u30ea\u30ea\u30fc\u30af (#26) \u3067\u306f\u3001\u30b9\u30e9\u30a4\u30b9\u307e\u305f\u306f\u914d\u5217\u306e\u30b9\u30e9\u30a4\u30b9\u304c\u30e1\u30e2\u30ea\u30ea\u30fc\u30af\u306e\u72b6\u6cc1\u3092\u5f15\u304d\u8d77\u3053\u3059\u53ef\u80fd\u6027\u304c\u3042\u308b\u3053\u3068\u3092\u78ba\u8a8d\u3057\u307e\u3057\u305f\u3002\u3053\u306e\u539f\u5247\u306f\u3001\u6587\u5b57\u5217\u304a\u3088\u3073\u90e8\u5206\u6587\u5b57\u5217\u306e\u64cd\u4f5c\u306b\u3082\u5f53\u3066\u306f\u307e\u308a\u307e\u3059\u3002
Go\u8a00\u8a9e\u3067\u90e8\u5206\u6587\u5b57\u5217\u64cd\u4f5c\u3092\u4f7f\u7528\u3059\u308b\u3068\u304d\u306f\u30012 \u3064\u306e\u3053\u3068\u306b\u7559\u610f\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u307e\u305a\u3001\u63d0\u4f9b\u3055\u308c\u308b\u9593\u9694\u306f\u30eb\u30fc\u30f3\u6570\u3067\u306f\u306a\u304f\u3001\u30d0\u30a4\u30c8\u6570\u306b\u57fa\u3065\u3044\u3066\u3044\u307e\u3059\u3002\u6b21\u306b\u3001\u7d50\u679c\u306e\u90e8\u5206\u6587\u5b57\u5217\u304c\u6700\u521d\u306e\u6587\u5b57\u5217\u3068\u540c\u3058\u30d0\u30c3\u30ad\u30f3\u30b0\u914d\u5217\u3092\u5171\u6709\u3059\u308b\u305f\u3081\u3001\u90e8\u5206\u6587\u5b57\u5217\u64cd\u4f5c\u306b\u3088\u308a\u30e1\u30e2\u30ea\u30ea\u30fc\u30af\u304c\u767a\u751f\u3059\u308b\u53ef\u80fd\u6027\u304c\u3042\u308a\u307e\u3059\u3002\u3053\u308c\u3092\u9632\u3050\u65b9\u6cd5\u306f\u3001\u6587\u5b57\u5217\u306e\u30b3\u30d4\u30fc\u3092\u624b\u52d5\u3067\u5b9f\u884c\u3059\u308b\u304b\u3001Go 1.18 \u304b\u3089\u5b9f\u88c5\u3055\u308c\u3066\u3044\u308b strings.Clone
\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u3067\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#_7","title":"\u95a2\u6570\u3068\u30e1\u30bd\u30c3\u30c9","text":""},{"location":"ja/#42","title":"\u3069\u306e\u578b\u306e\u30ec\u30b7\u30fc\u30d0\u30fc\u3092\u4f7f\u7528\u3059\u308c\u3070\u3088\u3044\u304b\u308f\u304b\u3063\u3066\u3044\u306a\u3044 (#42)","text":"\u8981\u7d04\u5024\u30ec\u30b7\u30fc\u30d0\u30fc\u3068\u30dd\u30a4\u30f3\u30bf\u30ec\u30b7\u30fc\u30d0\u30fc\u306e\u3069\u3061\u3089\u3092\u4f7f\u7528\u3059\u308b\u304b\u306f\u3001\u3069\u306e\u578b\u306a\u306e\u304b\u3001\u5909\u5316\u3055\u305b\u308b\u5fc5\u8981\u304c\u3042\u308b\u304b\u3069\u3046\u304b\u3001\u30b3\u30d4\u30fc\u3067\u304d\u306a\u3044\u30d5\u30a3\u30fc\u30eb\u30c9\u304c\u542b\u307e\u308c\u3066\u3044\u308b\u304b\u3069\u3046\u304b\u3001\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306f\u3069\u308c\u304f\u3089\u3044\u5927\u304d\u3044\u306e\u304b\u3001\u306a\u3069\u306e\u8981\u7d20\u306b\u57fa\u3065\u3044\u3066\u6c7a\u5b9a\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u5206\u304b\u3089\u306a\u3044\u5834\u5408\u306f\u3001\u30dd\u30a4\u30f3\u30bf\u30ec\u30b7\u30fc\u30d0\u3092\u4f7f\u7528\u3057\u3066\u304f\u3060\u3055\u3044\u3002
\u5024\u30ec\u30b7\u30fc\u30d0\u30fc\u3068\u30dd\u30a4\u30f3\u30bf\u30ec\u30b7\u30fc\u30d0\u30fc\u306e\u3069\u3061\u3089\u3092\u9078\u629e\u3059\u308b\u304b\u306f\u3001\u5fc5\u305a\u3057\u3082\u7c21\u5358\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u3002\u9078\u629e\u306b\u5f79\u7acb\u3064\u3044\u304f\u3064\u304b\u306e\u6761\u4ef6\u306b\u3064\u3044\u3066\u8aac\u660e\u3057\u307e\u3057\u3087\u3046\u3002
\u30dd\u30a4\u30f3\u30bf\u30ec\u30b7\u30fc\u30d0\u30fc\u3067\u306a\u3051\u308c\u3070\u306a\u3089\u306a\u3044 \u3068\u304d
type slice []int\n\nfunc (s *slice) add(element int) {\n *s = append(*s, element)\n}\n
\u30dd\u30a4\u30f3\u30bf\u30ec\u30b7\u30fc\u30d0\u30fc\u3067\u3042\u308b\u3079\u304d \u3068\u304d
\u5024\u30ec\u30b7\u30fc\u30d0\u30fc\u3067\u306a\u3051\u308c\u3070\u306a\u3089\u306a\u3044 \u3068\u304d
\u5024\u30ec\u30b7\u30fc\u30d0\u30fc\u3067\u3042\u308b\u3079\u304d \u3068\u304d
time.Time
\u306a\u3069\u306e\u5c0f\u3055\u306a\u914d\u5217\u307e\u305f\u306f\u69cb\u9020\u4f53\u3067\u3001\u53ef\u5909\u30d5\u30a3\u30fc\u30eb\u30c9\u3092\u6301\u305f\u306a\u3044\u5024\u578b\u3067\u3042\u308b\u5834\u5408\u3002 int
\u3001float64
\u3001\u307e\u305f\u306f string
\u306a\u3069\u306e\u57fa\u672c\u578b\u306e\u5834\u5408\u3002 \u3082\u3061\u308d\u3093\u3001\u7279\u6b8a\u306a\u30b1\u30fc\u30b9\u306f\u5e38\u306b\u5b58\u5728\u3059\u308b\u305f\u3081\u3001\u3059\u3079\u3066\u3092\u7db2\u7f85\u3059\u308b\u3053\u3068\u306f\u4e0d\u53ef\u80fd\u3067\u3059\u304c\u3001\u3053\u306e\u30bb\u30af\u30b7\u30e7\u30f3\u306e\u76ee\u6a19\u306f\u3001\u307b\u3068\u3093\u3069\u306e\u30b1\u30fc\u30b9\u3092\u30ab\u30d0\u30fc\u3059\u308b\u305f\u3081\u306e\u30ac\u30a4\u30c0\u30f3\u30b9\u3092\u63d0\u4f9b\u3059\u308b\u3053\u3068\u3067\u3059\u3002\u901a\u5e38\u306f\u3001\u305d\u3046\u3057\u306a\u3044\u6b63\u5f53\u306a\u7406\u7531\u304c\u306a\u3044\u9650\u308a\u3001\u5024\u30ec\u30b7\u30fc\u30d0\u30fc\u3092\u4f7f\u7528\u3057\u3066\u9593\u9055\u3044\u3042\u308a\u307e\u305b\u3093\u3002\u5206\u304b\u3089\u306a\u3044\u5834\u5408\u306f\u3001\u30dd\u30a4\u30f3\u30bf\u30ec\u30b7\u30fc\u30d0\u3092\u4f7f\u7528\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#43","title":"\u540d\u524d\u4ed8\u304d\u7d50\u679c\u30d1\u30e9\u30e1\u30fc\u30bf\u3092\u307e\u3063\u305f\u304f\u4f7f\u7528\u3057\u3066\u3044\u306a\u3044 (#43)","text":"\u8981\u7d04\u540d\u524d\u4ed8\u304d\u7d50\u679c\u30d1\u30e9\u30e1\u30fc\u30bf\u30fc\u306e\u4f7f\u7528\u306f\u3001\u7279\u306b\u8907\u6570\u306e\u7d50\u679c\u30d1\u30e9\u30e1\u30fc\u30bf\u30fc\u304c\u540c\u3058\u578b\u3092\u6301\u3064\u5834\u5408\u3001\u95a2\u6570\u30fb\u30e1\u30bd\u30c3\u30c9\u306e\u8aad\u307f\u3084\u3059\u3055\u3092\u5411\u4e0a\u3055\u305b\u308b\u52b9\u7387\u7684\u306a\u65b9\u6cd5\u3067\u3059\u3002\u5834\u5408\u306b\u3088\u3063\u3066\u306f\u3001\u540d\u524d\u4ed8\u304d\u7d50\u679c\u30d1\u30e9\u30e1\u30fc\u30bf\u306f\u30bc\u30ed\u5024\u306b\u521d\u671f\u5316\u3055\u308c\u308b\u305f\u3081\u3001\u3053\u306e\u65b9\u6cd5\u304c\u4fbf\u5229\u3067\u3059\u3089\u3042\u308b\u3053\u3068\u3082\u3042\u308a\u307e\u3059\u3002\u305f\u3060\u3057\u6f5c\u5728\u7684\u306a\u526f\u4f5c\u7528\u306b\u306f\u6ce8\u610f\u3057\u3066\u304f\u3060\u3055\u3044\u3002
\u95a2\u6570\u307e\u305f\u306f\u30e1\u30bd\u30c3\u30c9\u3067\u30d1\u30e9\u30e1\u30fc\u30bf\u3092\u8fd4\u3059\u3068\u304d\u3001\u3053\u308c\u3089\u306e\u30d1\u30e9\u30e1\u30fc\u30bf\u306b\u540d\u524d\u3092\u4ed8\u3051\u3066\u3001\u901a\u5e38\u306e\u5909\u6570\u3068\u3057\u3066\u4f7f\u7528\u3067\u304d\u307e\u3059\u3002\u7d50\u679c\u30d1\u30e9\u30e1\u30fc\u30bf\u30fc\u306b\u540d\u524d\u3092\u4ed8\u3051\u308b\u3068\u3001\u95a2\u6570\u30fb\u30e1\u30bd\u30c3\u30c9\u306e\u958b\u59cb\u6642\u306b\u305d\u306e\u30d1\u30e9\u30e1\u30fc\u30bf\u30fc\u306f\u30bc\u30ed\u5024\u306b\u521d\u671f\u5316\u3055\u308c\u307e\u3059\u3002\u540d\u524d\u4ed8\u304d\u7d50\u679c\u30d1\u30e9\u30e1\u30fc\u30bf\u3092\u4f7f\u7528\u3059\u308b\u3068\u3001 \u3080\u304d\u51fa\u3057\u306e return \u6587\uff08\u5f15\u6570\u306a\u3057\uff09 \u3092\u547c\u3073\u51fa\u3059\u3053\u3068\u3082\u3067\u304d\u307e\u3059\u3002\u305d\u306e\u5834\u5408\u3001\u7d50\u679c\u30d1\u30e9\u30e1\u30fc\u30bf\u306e\u73fe\u5728\u306e\u5024\u304c\u623b\u308a\u5024\u3068\u3057\u3066\u4f7f\u7528\u3055\u308c\u307e\u3059\u3002
\u4ee5\u4e0b\u306f\u3001\u540d\u524d\u4ed8\u304d\u7d50\u679c\u30d1\u30e9\u30e1\u30fc\u30bf b
\u3092\u7528\u3044\u305f\u4f8b\u3067\u3059\u3002
func f(a int) (b int) {\n b = a\n return\n}\n
\u3053\u306e\u4f8b\u3067\u306f\u3001\u7d50\u679c\u30d1\u30e9\u30e1\u30fc\u30bf\u306b\u540d\u524d b
\u3092\u4ed8\u3051\u3066\u3044\u307e\u3059\u3002\u5f15\u6570\u306a\u3057\u3067 return \u3092\u547c\u3073\u51fa\u3059\u3068\u3001b
\u306e\u73fe\u5728\u306e\u5024\u304c\u8fd4\u3055\u308c\u307e\u3059\u3002
\u5834\u5408\u306b\u3088\u3063\u3066\u306f\u3001\u540d\u524d\u4ed8\u304d\u306e\u7d50\u679c\u30d1\u30e9\u30e1\u30fc\u30bf\u30fc\u306b\u3088\u3063\u3066\u53ef\u8aad\u6027\u304c\u5411\u4e0a\u3059\u308b\u3053\u3068\u3082\u3042\u308a\u307e\u3059\u3002\u305f\u3068\u3048\u3070\u30012 \u3064\u306e\u30d1\u30e9\u30e1\u30fc\u30bf\u30fc\u304c\u540c\u3058\u578b\u3067\u3042\u308b\u5834\u5408\u306a\u3069\u3067\u3059\u3002\u305d\u306e\u4ed6\u306b\u3082\u3001\u5229\u4fbf\u6027\u306e\u305f\u3081\u306b\u7528\u3044\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u3086\u3048\u306b\u3001\u660e\u78ba\u306a\u5229\u70b9\u304c\u3042\u308b\u5834\u5408\u306f\u3001\u614e\u91cd\u306b\u306a\u308a\u306a\u304c\u3089\u3082\u540d\u524d\u4ed8\u304d\u7d50\u679c\u30d1\u30e9\u30e1\u30fc\u30bf\u3092\u4f7f\u7528\u3059\u308b\u3079\u304d\u3067\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#44","title":"\u540d\u524d\u4ed8\u304d\u7d50\u679c\u30d1\u30e9\u30e1\u30fc\u30bf\u306b\u3088\u308b\u4e88\u60f3\u5916\u306e\u526f\u4f5c\u7528 (#44)","text":"\u8981\u7d04#43 \u3092\u53c2\u7167\u3057\u3066\u304f\u3060\u3055\u3044\u3002
\u540d\u524d\u4ed8\u304d\u7d50\u679c\u30d1\u30e9\u30e1\u30fc\u30bf\u304c\u72b6\u6cc1\u306b\u3088\u3063\u3066\u306f\u5f79\u7acb\u3064\u7406\u7531\u306b\u3064\u3044\u3066\u8aac\u660e\u3057\u307e\u3057\u305f\u3002 \u305f\u3060\u3057\u3001\u3053\u308c\u3089\u306f\u30bc\u30ed\u5024\u306b\u521d\u671f\u5316\u3055\u308c\u308b\u305f\u3081\u3001\u5341\u5206\u306b\u6ce8\u610f\u3057\u306a\u3044\u3068\u3001\u8efd\u5fae\u306a\u30d0\u30b0\u304c\u767a\u751f\u3059\u308b\u53ef\u80fd\u6027\u304c\u3042\u308a\u307e\u3059\u3002\u305f\u3068\u3048\u3070\u3001\u3053\u306e\u30b3\u30fc\u30c9\u306f\u3069\u3053\u304c\u9593\u9055\u3063\u3066\u3044\u308b\u3067\u3057\u3087\u3046\u304b\u3002
func (l loc) getCoordinates(ctx context.Context, address string) (\n lat, lng float32, err error) {\n isValid := l.validateAddress(address) (1)\n if !isValid {\n return 0, 0, errors.New(\"invalid address\")\n }\n\n if ctx.Err() != nil { (2)\n return 0, 0, err\n }\n\n // \u5ea7\u6a19\u3092\u53d6\u5f97\u3057\u3066\u8fd4\u3059\n}\n
\u4e00\u77a5\u3057\u305f\u3060\u3051\u3067\u306f\u30a8\u30e9\u30fc\u306f\u660e\u3089\u304b\u3067\u306f\u306a\u3044\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002if ctx.Err() != nil
\u30b9\u30b3\u30fc\u30d7\u3067\u8fd4\u3055\u308c\u308b\u30a8\u30e9\u30fc\u306f err
\u3067\u3059\u3002\u3057\u304b\u3057\u3001err
\u5909\u6570\u306b\u306f\u5024\u3092\u5272\u308a\u5f53\u3066\u3066\u3044\u307e\u305b\u3093\u3002error
\u578b\u306e\u30bc\u30ed\u5024\u3001 nil
\u306b\u5272\u308a\u5f53\u3066\u3089\u308c\u305f\u307e\u307e\u3067\u3059\u3002\u3057\u305f\u304c\u3063\u3066\u3001\u3053\u306e\u30b3\u30fc\u30c9\u306f\u5e38\u306b nil \u30a8\u30e9\u30fc\u3092\u8fd4\u3057\u307e\u3059\u3002
\u540d\u524d\u4ed8\u304d\u7d50\u679c\u30d1\u30e9\u30e1\u30fc\u30bf\u3092\u4f7f\u7528\u3059\u308b\u5834\u5408\u3001\u5404\u30d1\u30e9\u30e1\u30fc\u30bf\u306f\u30bc\u30ed\u5024\u306b\u521d\u671f\u5316\u3055\u308c\u308b\u3053\u3068\u306b\u6ce8\u610f\u3057\u3066\u304f\u3060\u3055\u3044\u3002\u3053\u306e\u30bb\u30af\u30b7\u30e7\u30f3\u3067\u8aac\u660e\u3057\u305f\u3088\u3046\u306b\u3001\u3053\u308c\u306b\u3088\u308a\u3001\u898b\u3064\u3051\u308b\u306e\u304c\u5fc5\u305a\u3057\u3082\u7c21\u5358\u3067\u306f\u306a\u3044\u8efd\u5fae\u306a\u30d0\u30b0\u304c\u767a\u751f\u3059\u308b\u53ef\u80fd\u6027\u304c\u3042\u308a\u307e\u3059\u3002\u3086\u3048\u306b\u3001\u6f5c\u5728\u7684\u306a\u526f\u4f5c\u7528\u3092\u907f\u3051\u308b\u305f\u3081\u306b\u3001\u540d\u524d\u4ed8\u304d\u7d50\u679c\u30d1\u30e9\u30e1\u30fc\u30bf\u30fc\u3092\u4f7f\u7528\u3059\u308b\u3068\u304d\u306f\u6ce8\u610f\u3057\u3066\u304f\u3060\u3055\u3044\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#nil-45","title":"nil \u30ec\u30b7\u30fc\u30d0\u30fc\u3092\u8fd4\u3059 (#45)","text":"\u8981\u7d04\u30a4\u30f3\u30bf\u30d5\u30a7\u30fc\u30b9\u3092\u8fd4\u3059\u3068\u304d\u306f\u3001nil \u30dd\u30a4\u30f3\u30bf\u3092\u8fd4\u3059\u306e\u3067\u306f\u306a\u304f\u3001\u660e\u793a\u7684\u306a nil \u5024\u3092\u8fd4\u3059\u3088\u3046\u306b\u6ce8\u610f\u3057\u3066\u304f\u3060\u3055\u3044\u3002\u305d\u3046\u3057\u306a\u3051\u308c\u3070\u3001\u610f\u56f3\u3057\u306a\u3044\u7d50\u679c\u304c\u767a\u751f\u3057\u3001\u547c\u3073\u51fa\u3057\u5143\u304c nil \u3067\u306f\u306a\u3044\u5024\u3092\u53d7\u3051\u53d6\u308b\u53ef\u80fd\u6027\u304c\u3042\u308a\u307e\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#46","title":"\u95a2\u6570\u5165\u529b\u306b\u30d5\u30a1\u30a4\u30eb\u540d\u3092\u4f7f\u7528\u3057\u3066\u3044\u308b (#46)","text":"\u8981\u7d04\u30d5\u30a1\u30a4\u30eb\u540d\u306e\u4ee3\u308f\u308a\u306b io.Reader
\u578b\u3092\u53d7\u3051\u53d6\u308b\u3088\u3046\u306b\u95a2\u6570\u3092\u8a2d\u8a08\u3059\u308b\u3068\u3001\u95a2\u6570\u306e\u518d\u5229\u7528\u6027\u304c\u5411\u4e0a\u3057\u3001\u30c6\u30b9\u30c8\u304c\u5bb9\u6613\u306b\u306a\u308a\u307e\u3059\u3002
\u30d5\u30a1\u30a4\u30eb\u540d\u3092\u30d5\u30a1\u30a4\u30eb\u304b\u3089\u8aad\u307f\u53d6\u308b\u305f\u3081\u306e\u95a2\u6570\u5165\u529b\u3068\u3057\u3066\u53d7\u3051\u5165\u308c\u308b\u3053\u3068\u306f\u3001\u307b\u3068\u3093\u3069\u306e\u5834\u5408\u3001\u300c\u30b3\u30fc\u30c9\u306e\u81ed\u3044\u300d\u3068\u307f\u306a\u3055\u308c\u308b\u3079\u304d\u3067\u3059\uff08 os.Open
\u306a\u3069\u306e\u7279\u5b9a\u306e\u95a2\u6570\u3092\u9664\u304f\uff09\u3002\u8907\u6570\u306e\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3059\u308b\u3053\u3068\u306b\u306b\u306a\u308b\u304b\u3082\u3057\u308c\u305a\u3001\u5358\u4f53\u30c6\u30b9\u30c8\u304c\u3088\u308a\u8907\u96d1\u306b\u306a\u308b\u53ef\u80fd\u6027\u304c\u3042\u308b\u304b\u3089\u3067\u3059\u3002\u307e\u305f\u3001\u95a2\u6570\u306e\u518d\u5229\u7528\u6027\u3082\u4f4e\u4e0b\u3057\u307e\u3059 \uff08\u305f\u3060\u3057\u3001\u3059\u3079\u3066\u306e\u95a2\u6570\u304c\u518d\u5229\u7528\u3055\u308c\u308b\u308f\u3051\u3067\u306f\u3042\u308a\u307e\u305b\u3093\uff09\u3002 io.Reader
\u30a4\u30f3\u30bf\u30d5\u30a7\u30fc\u30b9\u3092\u4f7f\u7528\u3059\u308b\u3068\u3001\u30c7\u30fc\u30bf\u30bd\u30fc\u30b9\u304c\u62bd\u8c61\u5316\u3055\u308c\u307e\u3059\u3002\u5165\u529b\u304c\u30d5\u30a1\u30a4\u30eb\u3001\u6587\u5b57\u5217\u3001HTTP \u30ea\u30af\u30a8\u30b9\u30c8\u3001gRPC \u30ea\u30af\u30a8\u30b9\u30c8\u306e\u3044\u305a\u308c\u3067\u3042\u308b\u304b\u306b\u95a2\u4fc2\u306a\u304f\u3001\u5b9f\u88c5\u306f\u518d\u5229\u7528\u3067\u304d\u3001\u7c21\u5358\u306b\u30c6\u30b9\u30c8\u3067\u304d\u307e\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#defer-47","title":"defer
\u5f15\u6570\u3068\u30ec\u30b7\u30fc\u30d0\u30fc\u304c\u3069\u306e\u3088\u3046\u306b\u8a55\u4fa1\u3055\u308c\u308b\u304b\u3092\u77e5\u3089\u306a\u3044\uff08\u5f15\u6570\u306e\u8a55\u4fa1\u3001\u30dd\u30a4\u30f3\u30bf\u30fc\u3001\u304a\u3088\u3073\u5024\u30ec\u30b7\u30fc\u30d0\u30fc\uff09 (#47)","text":"\u8981\u7d04 \u30dd\u30a4\u30f3\u30bf\u3092 defer
\u95a2\u6570\u306b\u6e21\u3059\u3053\u3068\u3068\u3001\u547c\u3073\u51fa\u3057\u3092\u30af\u30ed\u30fc\u30b8\u30e3\u5185\u306b\u30e9\u30c3\u30d7\u3059\u308b\u3053\u3068\u304c\u3001\u5f15\u6570\u3068\u30ec\u30b7\u30fc\u30d0\u30fc\u306e\u5373\u6642\u8a55\u4fa1\u3092\u514b\u670d\u3059\u308b\u305f\u3081\u306b\u5b9f\u73fe\u53ef\u80fd\u306a\u89e3\u6c7a\u7b56\u3067\u3059\u3002
defer
\u95a2\u6570\u3067\u306f\u3001\u5f15\u6570\u306f\u3001\u4e0a\u4f4d\u30d6\u30ed\u30c3\u30af\u306e\u95a2\u6570\u304c\u623b\u3063\u3066\u304b\u3089\u3067\u306f\u306a\u304f\u3001\u3059\u3050\u306b\u8a55\u4fa1\u3055\u308c\u307e\u3059\u3002\u305f\u3068\u3048\u3070\u3001\u3053\u306e\u30b3\u30fc\u30c9\u3067\u306f\u3001\u5e38\u306b\u540c\u3058\u30b9\u30c6\u30fc\u30bf\u30b9\u2015\u2015\u7a7a\u306e\u6587\u5b57\u5217\u2015\u2015\u3067 notify
\u3068 incrementCounter
\u3092\u547c\u3073\u51fa\u3057\u307e\u3059\u3002
const (\n StatusSuccess = \"success\"\n StatusErrorFoo = \"error_foo\"\n StatusErrorBar = \"error_bar\"\n)\n\nfunc f() error {\n var status string\n defer notify(status)\n defer incrementCounter(status)\n\n if err := foo(); err != nil {\n status = StatusErrorFoo\n return err\n }\n\n if err := bar(); err != nil {\n status = StatusErrorBar\n return err\n }\n\n status = StatusSuccess <5>\n return nil\n}\n
\u305f\u3057\u304b\u306b\u3001notify(status)
\u3068 incrementCounter(status)
\u3092 defer
\u95a2\u6570\u3068\u3057\u3066\u547c\u3073\u51fa\u3057\u3066\u3044\u307e\u3059\u3002\u3057\u305f\u304c\u3063\u3066\u3001Go\u8a00\u8a9e\u306f\u3001defer \u3092\u4f7f\u7528\u3057\u305f\u6bb5\u968e\u3067 f
\u304c\u30b9\u30c6\u30fc\u30bf\u30b9\u306e\u73fe\u5728\u306e\u5024\u3092\u8fd4\u3059\u3068\u3001\u3053\u308c\u3089\u306e\u547c\u3073\u51fa\u3057\u306e\u5b9f\u884c\u3092\u9045\u3089\u305b\u3001\u7a7a\u306e\u6587\u5b57\u5217\u3092\u6e21\u3057\u307e\u3059\u3002
defer
\u3092\u4f7f\u3044\u7d9a\u3051\u305f\u3044\u5834\u5408\u306e\u4e3b\u306a\u65b9\u6cd5\u306f 2 \u3064\u3042\u308a\u307e\u3059\u3002
\u6700\u521d\u306e\u89e3\u6c7a\u7b56\u306f\u6587\u5b57\u5217\u30dd\u30a4\u30f3\u30bf\u3092\u6e21\u3059\u3053\u3068\u3067\u3059\u3002
func f() error {\n var status string\n defer notify(&status) \n defer incrementCounter(&status)\n\n // \u95a2\u6570\u306e\u305d\u308c\u4ee5\u5916\u306e\u90e8\u5206\u306f\u5909\u66f4\u306a\u3057\n}\n
defer
\u3092\u4f7f\u7528\u3059\u308b\u3068\u3001\u5f15\u6570\uff08\u3053\u3053\u3067\u306f\u30b9\u30c6\u30fc\u30bf\u30b9\u306e\u30a2\u30c9\u30ec\u30b9\uff09\u304c\u3059\u3050\u306b\u8a55\u4fa1\u3055\u308c\u307e\u3059\u3002\u30b9\u30c6\u30fc\u30bf\u30b9\u81ea\u4f53\u306f\u95a2\u6570\u5168\u4f53\u3067\u5909\u66f4\u3055\u308c\u307e\u3059\u304c\u3001\u305d\u306e\u30a2\u30c9\u30ec\u30b9\u306f\u5272\u308a\u5f53\u3066\u306b\u95a2\u4fc2\u306a\u304f\u4e00\u5b9a\u306e\u307e\u307e\u3067\u3059\u3002\u3088\u3063\u3066\u3001notify
\u307e\u305f\u306f incrementCounter
\u304c\u6587\u5b57\u5217\u30dd\u30a4\u30f3\u30bf\u306b\u3088\u3063\u3066\u53c2\u7167\u3055\u308c\u308b\u5024\u3092\u4f7f\u7528\u3059\u308b\u5834\u5408\u3001\u671f\u5f85\u3069\u304a\u308a\u306b\u52d5\u4f5c\u3057\u307e\u3059\u3002\u305f\u3060\u3057\u3001\u3053\u306e\u89e3\u6c7a\u7b56\u3067\u306f 2 \u3064\u306e\u95a2\u6570\u306e\u30b7\u30b0\u30cd\u30c1\u30e3\u3092\u5909\u66f4\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u3001\u305d\u308c\u304c\u5e38\u306b\u53ef\u80fd\u3067\u3042\u308b\u3068\u306f\u9650\u308a\u307e\u305b\u3093\u3002
\u5225\u306e\u89e3\u6c7a\u7b56\u304c\u3042\u308a\u307e\u3059\u2015\u2015\u30af\u30ed\u30fc\u30b8\u30e3\uff08\u672c\u4f53\u306e\u5916\u90e8\u304b\u3089\u5909\u6570\u3092\u53c2\u7167\u3059\u308b\u533f\u540d\u95a2\u6570\u5024\uff09\u3092 defer
\u6587\u3068\u3057\u3066\u547c\u3073\u51fa\u3059\u3053\u3068\u3067\u3059\u3002
func f() error {\n var status string\n defer func() {\n notify(status)\n incrementCounter(status)\n }()\n\n // \u95a2\u6570\u306e\u305d\u308c\u4ee5\u5916\u306e\u90e8\u5206\u306f\u5909\u66f4\u306a\u3057\n}\n
\u3053\u3053\u3067\u306f\u3001notify
\u3068 incrementCounter
\u306e\u4e21\u65b9\u306e\u547c\u3073\u51fa\u3057\u3092\u30af\u30ed\u30fc\u30b8\u30e3\u5185\u306b\u30e9\u30c3\u30d7\u3057\u307e\u3059\u3002\u3053\u306e\u30af\u30ed\u30fc\u30b8\u30e3\u306f\u3001\u672c\u4f53\u306e\u5916\u90e8\u304b\u3089\u30b9\u30c6\u30fc\u30bf\u30b9\u5909\u6570\u3092\u53c2\u7167\u3057\u307e\u3059\u3002\u3086\u3048\u306b\u3001status
\u306f\u3001defer
\u3092\u547c\u3073\u51fa\u3057\u305f\u3068\u304d\u3067\u306f\u306a\u304f\u3001\u30af\u30ed\u30fc\u30b8\u30e3\u304c\u5b9f\u884c\u3055\u308c\u305f\u3068\u304d\u306b\u8a55\u4fa1\u3055\u308c\u307e\u3059\u3002\u3053\u306e\u89e3\u6c7a\u7b56\u306f\u6b63\u3057\u304f\u6a5f\u80fd\u3059\u308b\u4e0a\u306b\u3001\u30b7\u30b0\u30cd\u30c1\u30e3\u3092\u5909\u66f4\u3059\u308b\u305f\u3081\u306b notify
\u3084 incrementCounter
\u3092\u5fc5\u8981\u3068\u3057\u307e\u305b\u3093\u3002
\u3053\u306e\u52d5\u4f5c\u306f\u30e1\u30bd\u30c3\u30c9\u30ec\u30b7\u30fc\u30d0\u30fc\u306b\u3082\u9069\u7528\u3055\u308c\u308b\u3053\u3068\u306b\u3082\u6ce8\u610f\u3057\u3066\u304f\u3060\u3055\u3044\u3002\u30ec\u30b7\u30fc\u30d0\u30fc\u306f\u3059\u3050\u306b\u8a55\u4fa1\u3055\u308c\u307e\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#_8","title":"\u30a8\u30e9\u30fc\u51e6\u7406","text":""},{"location":"ja/#48","title":"\u30d1\u30cb\u30c3\u30af (#48)","text":"\u8981\u7d04panic
\u306e\u4f7f\u7528\u306f\u3001Go\u8a00\u8a9e\u3067\u30a8\u30e9\u30fc\u306b\u5bfe\u51e6\u3059\u308b\u305f\u3081\u306e\u624b\u6bb5\u3067\u3059\u3002\u305f\u3060\u3057\u3001\u3053\u308c\u306f\u56de\u5fa9\u4e0d\u80fd\u306a\u72b6\u6cc1\u3067\u306e\u307f\u4f7f\u7528\u3059\u308b\u3088\u3046\u306b\u3057\u3066\u304f\u3060\u3055\u3044\u3002\u305f\u3068\u3048\u3070\u3001\u30d2\u30e5\u30fc\u30de\u30f3\u30a8\u30e9\u30fc\u3092\u901a\u77e5\u3059\u308b\u5834\u5408\u3084\u3001\u5fc5\u9808\u306e\u4f9d\u5b58\u95a2\u4fc2\u306e\u8aad\u307f\u8fbc\u307f\u306b\u5931\u6557\u3057\u305f\u5834\u5408\u306a\u3069\u3067\u3059\u3002
Go\u8a00\u8a9e\u3067\u306f\u3001panic \u306f\u901a\u5e38\u306e\u6d41\u308c\u3092\u505c\u6b62\u3059\u308b\u7d44\u307f\u8fbc\u307f\u95a2\u6570\u3067\u3059\u3002
func main() {\n fmt.Println(\"a\")\n panic(\"foo\")\n fmt.Println(\"b\")\n}\n
\u3053\u306e\u30b3\u30fc\u30c9\u306f a \u3092\u51fa\u529b\u3057\u3001b \u3092\u51fa\u529b\u3059\u308b\u524d\u306b\u505c\u6b62\u3057\u307e\u3059\u3002
a\npanic: foo\n\ngoroutine 1 [running]:\nmain.main()\n main.go:7 +0xb3\n
panic \u306e\u4f7f\u7528\u306f\u614e\u91cd\u306b\u3059\u3079\u304d\u3067\u3059\u3002\u4ee3\u8868\u7684\u306a\u30b1\u30fc\u30b9\u304c 2 \u3064\u3042\u308a\u30011 \u3064\u306f\u30d2\u30e5\u30fc\u30de\u30f3\u30a8\u30e9\u30fc\u3092\u901a\u77e5\u3059\u308b\u5834\u5408\uff08\u4f8b: sql.Register
\u30c9\u30e9\u30a4\u30d0\u30fc\u304c nil
\u307e\u305f\u306f\u65e2\u306b\u767b\u9332\u3055\u308c\u3066\u3044\u308b\u5834\u5408\u306b panic \u3092\u8d77\u3053\u3057\u307e\u3059\uff09\u3001\u3082\u3046 1 \u3064\u306f\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u304c\u5fc5\u9808\u306e\u4f9d\u5b58\u95a2\u4fc2\u306e\u751f\u6210\u306b\u5931\u6557\u3057\u305f\u5834\u5408\u3067\u3059\u3002\u7d50\u679c\u3068\u3057\u3066\u3001\u4f8b\u5916\u7684\u306b\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u505c\u6b62\u3057\u307e\u3059\u3002\u305d\u308c\u4ee5\u5916\u306e\u307b\u3068\u3093\u3069\u306e\u5834\u5408\u306b\u304a\u3044\u3066\u306f\u3001\u30a8\u30e9\u30fc\u51e6\u7406\u306f\u3001\u6700\u5f8c\u306e\u623b\u308a\u5f15\u6570\u3068\u3057\u3066\u9069\u5207\u306a\u30a8\u30e9\u30fc\u578b\u3092\u8fd4\u3059\u95a2\u6570\u3092\u901a\u3058\u3066\u884c\u3046\u3079\u304d\u3067\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#49","title":"\u30a8\u30e9\u30fc\u3092\u30e9\u30c3\u30d7\u3059\u3079\u304d\u3068\u304d\u3092\u77e5\u3089\u306a\u3044 (#49)","text":"\u8981\u7d04\u30a8\u30e9\u30fc\u3092\u30e9\u30c3\u30d7\u3059\u308b\u3068\u3001\u30a8\u30e9\u30fc\u3092\u30de\u30fc\u30af\u3057\u305f\u308a\u3001\u8ffd\u52a0\u306e\u30b3\u30f3\u30c6\u30ad\u30b9\u30c8\u3092\u63d0\u4f9b\u3057\u305f\u308a\u3067\u304d\u307e\u3059\u3002\u305f\u3060\u3057\u3001\u30a8\u30e9\u30fc\u30e9\u30c3\u30d4\u30f3\u30b0\u306b\u3088\u308a\u3001\u547c\u3073\u51fa\u3057\u5143\u304c\u30bd\u30fc\u30b9\u30a8\u30e9\u30fc\u3092\u5229\u7528\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308b\u305f\u3081\u3001\u6f5c\u5728\u7684\u306a\u7d50\u5408\u304c\u767a\u751f\u3057\u307e\u3059\u3002\u305d\u308c\u3092\u907f\u3051\u305f\u3044\u5834\u5408\u306f\u3001\u30a8\u30e9\u30fc\u30e9\u30c3\u30d4\u30f3\u30b0\u3092\u4f7f\u7528\u3057\u306a\u3044\u3067\u304f\u3060\u3055\u3044\u3002
Go 1.13 \u4ee5\u964d\u3001%w \u30c7\u30a3\u30ec\u30af\u30c6\u30a3\u30d6\u3092\u4f7f\u7528\u3059\u308c\u3070\u7c21\u5358\u306b\u30a8\u30e9\u30fc\u3092\u30e9\u30c3\u30d7\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u3002\u30a8\u30e9\u30fc\u30e9\u30c3\u30d4\u30f3\u30b0\u3068\u306f\u3001\u30bd\u30fc\u30b9\u30a8\u30e9\u30fc\u3082\u4f7f\u7528\u3067\u304d\u308b\u3088\u3046\u306b\u3059\u308b\u30e9\u30c3\u30d1\u30fc\u30b3\u30f3\u30c6\u30ca\u5185\u3067\u30a8\u30e9\u30fc\u3092\u30e9\u30c3\u30d7\u307e\u305f\u306f\u30d1\u30c3\u30af\u3059\u308b\u3053\u3068\u3067\u3059\u3002\u4e00\u822c\u306b\u3001\u30a8\u30e9\u30fc\u30e9\u30c3\u30d4\u30f3\u30b0\u306e\u4e3b\u306a\u4f7f\u7528\u4f8b\u306f\u6b21\u306e 2 \u3064\u3067\u3059\u3002
\u30a8\u30e9\u30fc\u3092\u51e6\u7406\u3059\u308b\u3068\u304d\u3001\u30a8\u30e9\u30fc\u3092\u30e9\u30c3\u30d7\u3059\u308b\u304b\u3069\u3046\u304b\u3092\u6c7a\u5b9a\u3067\u304d\u307e\u3059\u3002\u30e9\u30c3\u30d4\u30f3\u30b0\u3068\u306f\u3001\u30a8\u30e9\u30fc\u306b\u3055\u3089\u306b\u30b3\u30f3\u30c6\u30ad\u30b9\u30c8\u3092\u8ffd\u52a0\u3057\u305f\u308a\u3001\u30a8\u30e9\u30fc\u3092\u7279\u5b9a\u306e\u30bf\u30a4\u30d7\u3068\u3057\u3066\u30de\u30fc\u30af\u3057\u305f\u308a\u3059\u308b\u3053\u3068\u3067\u3059\u3002\u30a8\u30e9\u30fc\u3092\u30de\u30fc\u30af\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u5834\u5408\u306f\u3001\u72ec\u81ea\u306e\u30a8\u30e9\u30fc\u578b\u3092\u4f5c\u6210\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u3067\u3059\u304c\u3001\u65b0\u305f\u306b\u30b3\u30f3\u30c6\u30ad\u30b9\u30c8\u3092\u52a0\u3048\u305f\u3044\u3060\u3051\u306e\u5834\u5408\u306f\u3001\u65b0\u3057\u3044\u30a8\u30e9\u30fc\u578b\u3092\u4f5c\u6210\u3059\u308b\u5fc5\u8981\u304c\u306a\u3044\u305f\u3081\u3001%w \u30c7\u30a3\u30ec\u30af\u30c6\u30a3\u30d6\u3092\u6307\u5b9a\u3057\u3066 fmt.Errorf \u3092\u4f7f\u7528\u3057\u307e\u3057\u3087\u3046\u3002\u305f\u3060\u3057\u3001\u30a8\u30e9\u30fc\u30e9\u30c3\u30d4\u30f3\u30b0\u306b\u3088\u308a\u3001\u547c\u3073\u51fa\u3057\u5143\u304c\u30bd\u30fc\u30b9\u30a8\u30e9\u30fc\u3092\u5229\u7528\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308b\u305f\u3081\u3001\u6f5c\u5728\u7684\u306a\u7d50\u5408\u304c\u751f\u3058\u307e\u3059\u3002\u305d\u308c\u3092\u907f\u3051\u305f\u3044\u5834\u5408\u306f\u3001\u30a8\u30e9\u30fc\u306e\u30e9\u30c3\u30d4\u30f3\u30b0\u3067\u306f\u306a\u304f\u3001\u30a8\u30e9\u30fc\u306e\u5909\u63db\u3092\u4f7f\u7528\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u305f\u3068\u3048\u3070\u3001%v \u30c7\u30a3\u30ec\u30af\u30c6\u30a3\u30d6\u3092\u6307\u5b9a\u3057\u305f fmt.Errorf \u3092\u4f7f\u7528\u3057\u307e\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#50","title":"\u30a8\u30e9\u30fc\u578b\u306e\u4e0d\u6b63\u306a\u6bd4\u8f03 (#50)","text":"\u8981\u7d04Go 1.13 \u306e\u30a8\u30e9\u30fc\u30e9\u30c3\u30d4\u30f3\u30b0\u3092 %w
\u30c7\u30a3\u30ec\u30af\u30c6\u30a3\u30d6\u3068 fmt.Errorf
\u3067\u4f7f\u7528\u3059\u308b\u5834\u5408\u3001\u578b\u306b\u5bfe\u3059\u308b\u30a8\u30e9\u30fc\u306e\u6bd4\u8f03\u306f errors.As
\u3092\u901a\u3058\u3066\u884c\u3046\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u305d\u3046\u3067\u306a\u3051\u308c\u3070\u3001\u8fd4\u3055\u308c\u305f\u30a8\u30e9\u30fc\u304c\u30e9\u30c3\u30d7\u3055\u308c\u3066\u3044\u308b\u5834\u5408\u3001\u8a55\u4fa1\u306b\u5931\u6557\u3057\u307e\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#51","title":"\u30a8\u30e9\u30fc\u5024\u306e\u4e0d\u6b63\u306a\u6bd4\u8f03 (#51)","text":"\u8981\u7d04Go 1.13 \u306e\u30a8\u30e9\u30fc\u30e9\u30c3\u30d4\u30f3\u30b0\u3092 %w
\u30c7\u30a3\u30ec\u30af\u30c6\u30a3\u30d6\u3068 fmt.Errorf
\u3067\u4f7f\u7528\u3059\u308b\u5834\u5408\u3001\u30a8\u30e9\u30fc\u3068\u5024\u306e\u6bd4\u8f03\u306f errors.As
\u3092\u901a\u3058\u3066\u884c\u3046\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u305d\u3046\u3067\u306a\u3051\u308c\u3070\u3001\u8fd4\u3055\u308c\u305f\u30a8\u30e9\u30fc\u304c\u30e9\u30c3\u30d7\u3055\u308c\u3066\u3044\u308b\u5834\u5408\u3001\u8a55\u4fa1\u306b\u5931\u6557\u3057\u307e\u3059\u3002
\u30bb\u30f3\u30c1\u30cd\u30eb\u30a8\u30e9\u30fc\u306f\u30b0\u30ed\u30fc\u30d0\u30eb\u5909\u6570\u3068\u3057\u3066\u5b9a\u7fa9\u3055\u308c\u305f\u30a8\u30e9\u30fc\u306e\u3053\u3068\u3067\u3059\u3002
import \"errors\"\n\nvar ErrFoo = errors.New(\"foo\")\n
\u4e00\u822c\u306b\u3001\u6163\u4f8b\u3068\u3057\u3066 Err
\u3067\u59cb\u3081\u3001\u305d\u306e\u5f8c\u306b\u30a8\u30e9\u30fc\u578b\u3092\u7d9a\u3051\u307e\u3059\u3002\u3053\u3053\u3067\u306f ErrFoo
\u3067\u3059\u3002\u30bb\u30f3\u30c1\u30cd\u30eb\u30a8\u30e9\u30fc\u306f\u3001\u4e88\u671f\u3055\u308c\u308b \u30a8\u30e9\u30fc\u3001\u3064\u307e\u308a\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u304c\u78ba\u8a8d\u3059\u308b\u3053\u3068\u3092\u671f\u5f85\u3059\u308b\u30a8\u30e9\u30fc\u3092\u4f1d\u3048\u307e\u3059\u3002\u4e00\u822c\u7684\u306a\u30ac\u30a4\u30c9\u30e9\u30a4\u30f3\u3068\u3057\u3066 var ErrFoo =errors.New(\"foo\")
\u3002 BarError
\u306f error
\u30a4\u30f3\u30bf\u30d5\u30a7\u30fc\u30b9\u3092\u5b9f\u88c5\u3057\u305f\u4e0a\u3067 type BarError struct { ... }
\u3002 \u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3067 %w
\u30c7\u30a3\u30ec\u30af\u30c6\u30a3\u30d6\u3068 fmt.Errorf
\u3092\u4f7f\u7528\u3057\u3066\u30a8\u30e9\u30fc\u30e9\u30c3\u30d7\u3092\u4f7f\u7528\u3059\u308b\u5834\u5408\u3001\u7279\u5b9a\u306e\u5024\u306b\u5bfe\u3059\u308b\u30a8\u30e9\u30fc\u306e\u30c1\u30a7\u30c3\u30af\u306f ==
\u306e\u4ee3\u308f\u308a\u306b errors.Is
\u3092\u4f7f\u7528\u3057\u3066\u884c\u3044\u307e\u3057\u3087\u3046\u3002\u305d\u308c\u306b\u3088\u3063\u3066\u3001\u30bb\u30f3\u30c1\u30cd\u30eb\u30a8\u30e9\u30fc\u304c\u30e9\u30c3\u30d7\u3055\u308c\u3066\u3044\u308b\u5834\u5408\u3067\u3082\u3001errors.Is
\u306f\u305d\u308c\u3092\u518d\u5e30\u7684\u306b\u30a2\u30f3\u30e9\u30c3\u30d7\u3057\u3001\u30c1\u30a7\u30fc\u30f3\u5185\u306e\u5404\u30a8\u30e9\u30fc\u3092\u63d0\u4f9b\u3055\u308c\u305f\u5024\u3068\u6bd4\u8f03\u3067\u304d\u307e\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#2-52","title":"\u30a8\u30e9\u30fc\u306e 2 \u56de\u51e6\u7406 (#52)","text":"\u8981\u7d04\u307b\u3068\u3093\u3069\u306e\u5834\u5408\u3001\u30a8\u30e9\u30fc\u306f 1 \u56de\u3067\u51e6\u7406\u3055\u308c\u308b\u3079\u304d\u3067\u3059\u3002\u30a8\u30e9\u30fc\u3092\u30ed\u30b0\u306b\u8a18\u9332\u3059\u308b\u3053\u3068\u306f\u3001\u30a8\u30e9\u30fc\u3092\u51e6\u7406\u3059\u308b\u3053\u3068\u3067\u3059\u3002\u3059\u306a\u308f\u3061\u3001\u30ed\u30b0\u306b\u8a18\u9332\u3059\u308b\u304b\u30a8\u30e9\u30fc\u3092\u8fd4\u3059\u304b\u3092\u9078\u629e\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u591a\u304f\u306e\u5834\u5408\u3001\u30a8\u30e9\u30fc\u30e9\u30c3\u30d4\u30f3\u30b0\u306f\u3001\u30a8\u30e9\u30fc\u306b\u8ffd\u52a0\u306e\u30b3\u30f3\u30c6\u30ad\u30b9\u30c8\u3092\u63d0\u4f9b\u3057\u3001\u30bd\u30fc\u30b9\u30a8\u30e9\u30fc\u3092\u8fd4\u3059\u3053\u3068\u304c\u3067\u304d\u308b\u305f\u3081\u3001\u89e3\u6c7a\u7b56\u306b\u306a\u308a\u307e\u3059\u3002
\u30a8\u30e9\u30fc\u3092\u8907\u6570\u56de\u51e6\u7406\u3059\u308b\u3053\u3068\u306f\u3001\u7279\u306bGo\u8a00\u8a9e\u306b\u9650\u3089\u305a\u3001\u958b\u767a\u8005\u304c\u983b\u7e41\u306b\u3084\u3063\u3066\u3057\u307e\u3046\u30df\u30b9\u3067\u3059\u3002\u3053\u308c\u306b\u3088\u308a\u3001\u540c\u3058\u30a8\u30e9\u30fc\u304c\u8907\u6570\u56de\u30ed\u30b0\u306b\u8a18\u9332\u3055\u308c\u3001\u30c7\u30d0\u30c3\u30b0\u304c\u56f0\u96e3\u306b\u306a\u308b\u72b6\u6cc1\u304c\u767a\u751f\u3059\u308b\u53ef\u80fd\u6027\u304c\u3042\u308a\u307e\u3059\u3002
\u30a8\u30e9\u30fc\u51e6\u7406\u306f 1 \u5ea6\u3067\u6e08\u307e\u3059\u3079\u304d\u3060\u3068\u3044\u3046\u3053\u3068\u3092\u899a\u3048\u3066\u304a\u304d\u307e\u3057\u3087\u3046\u3002\u30a8\u30e9\u30fc\u3092\u30ed\u30b0\u306b\u8a18\u9332\u3059\u308b\u3053\u3068\u306f\u3001\u30a8\u30e9\u30fc\u3092\u51e6\u7406\u3059\u308b\u3053\u3068\u3067\u3059\u3002\u3064\u307e\u308a\u3001\u884c\u3046\u3079\u304d\u306f\u3001\u30ed\u30b0\u306b\u8a18\u9332\u3059\u308b\u304b\u3001\u30a8\u30e9\u30fc\u3092\u8fd4\u3059\u304b\u306e\u3069\u3061\u3089\u304b\u3060\u3068\u3044\u3046\u3053\u3068\u3067\u3059\u3002\u3053\u308c\u306b\u3088\u308a\u3001\u30b3\u30fc\u30c9\u304c\u7c21\u7d20\u5316\u3055\u308c\u3001\u30a8\u30e9\u30fc\u306e\u72b6\u6cc1\u306b\u3064\u3044\u3066\u3088\u308a\u9069\u5207\u306a\u6d1e\u5bdf\u304c\u5f97\u3089\u308c\u307e\u3059\u3002\u30a8\u30e9\u30fc\u30e9\u30c3\u30d4\u30f3\u30b0\u306f\u3001\u30bd\u30fc\u30b9\u30a8\u30e9\u30fc\u3092\u4f1d\u3048\u3001\u30a8\u30e9\u30fc\u306b\u30b3\u30f3\u30c6\u30ad\u30b9\u30c8\u3092\u8ffd\u52a0\u3067\u304d\u308b\u305f\u3081\u3001\u6700\u3082\u4f7f\u3044\u52dd\u624b\u306e\u826f\u3044\u624b\u6bb5\u306b\u306a\u308a\u307e\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#53","title":"\u30a8\u30e9\u30fc\u51e6\u7406\u3092\u3057\u306a\u3044 (#53)","text":"\u8981\u7d04\u95a2\u6570\u547c\u3073\u51fa\u3057\u4e2d\u3067\u3042\u3063\u3066\u3082\u3001defer
\u95a2\u6570\u5185\u3067\u3042\u3063\u3066\u3082\u3001\u30a8\u30e9\u30fc\u3092\u7121\u8996\u3059\u308b\u3068\u304d\u306f\u3001\u30d6\u30e9\u30f3\u30af\u8b58\u5225\u5b50\u3092\u4f7f\u7528\u3057\u3066\u660e\u78ba\u306b\u884c\u3046\u3079\u304d\u3067\u3059\u3002\u305d\u3046\u3057\u306a\u3044\u3068\u3001\u5c06\u6765\u306e\u8aad\u307f\u624b\u304c\u305d\u308c\u304c\u610f\u56f3\u7684\u3060\u3063\u305f\u306e\u304b\u3001\u305d\u308c\u3068\u3082\u30df\u30b9\u3060\u3063\u305f\u306e\u304b\u56f0\u60d1\u3059\u308b\u53ef\u80fd\u6027\u304c\u3042\u308a\u307e\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#defer-54","title":"defer
\u30a8\u30e9\u30fc\u3092\u51e6\u7406\u3057\u306a\u3044 (#54)","text":"\u8981\u7d04 \u591a\u304f\u306e\u5834\u5408\u3001defer
\u95a2\u6570\u306b\u3088\u3063\u3066\u8fd4\u3055\u308c\u308b\u30a8\u30e9\u30fc\u3092\u7121\u8996\u3059\u3079\u304d\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u3002\u72b6\u6cc1\u306b\u5fdc\u3058\u3066\u3001\u76f4\u63a5\u51e6\u7406\u3059\u308b\u304b\u3001\u547c\u3073\u51fa\u3057\u5143\u306b\u4f1d\u3048\u307e\u3057\u3087\u3046\u3002\u3053\u308c\u3092\u7121\u8996\u3059\u308b\u5834\u5408\u306f\u3001\u30d6\u30e9\u30f3\u30af\u8b58\u5225\u5b50\u3092\u4f7f\u7528\u3057\u3066\u304f\u3060\u3055\u3044\u3002
\u6b21\u306e\u30b3\u30fc\u30c9\u3092\u8003\u3048\u3066\u307f\u307e\u3057\u3087\u3046\u3002
func f() {\n // ...\n notify() // \u30a8\u30e9\u30fc\u51e6\u7406\u306f\u7701\u7565\u3055\u308c\u3066\u3044\u307e\u3059\n}\n\nfunc notify() error {\n // ...\n}\n
\u4fdd\u5b88\u6027\u306e\u89b3\u70b9\u304b\u3089\u3001\u3053\u306e\u30b3\u30fc\u30c9\u306f\u3044\u304f\u3064\u304b\u306e\u554f\u984c\u3092\u5f15\u304d\u8d77\u3053\u3059\u53ef\u80fd\u6027\u304c\u3042\u308a\u307e\u3059\u3002\u3042\u308b\u4eba\u304c\u3053\u308c\u3092\u8aad\u3080\u3053\u3068\u3092\u8003\u3048\u3066\u307f\u307e\u3059\u3002\u8aad\u307f\u624b\u306f\u3001notify \u304c\u30a8\u30e9\u30fc\u3092\u8fd4\u3059\u306b\u3082\u304b\u304b\u308f\u3089\u305a\u3001\u305d\u306e\u30a8\u30e9\u30fc\u304c\u89aa\u95a2\u6570\u306b\u3088\u3063\u3066\u51e6\u7406\u3055\u308c\u306a\u3044\u3053\u3068\u306b\u6c17\u3065\u304d\u307e\u3059\u3002\u30a8\u30e9\u30fc\u51e6\u7406\u304c\u610f\u56f3\u7684\u3067\u3042\u308b\u304b\u3069\u3046\u304b\u3092\u679c\u305f\u3057\u3066\u63a8\u6e2c\u3067\u304d\u308b\u3067\u3057\u3087\u3046\u304b\u3002\u4ee5\u524d\u306e\u958b\u767a\u8005\u304c\u305d\u308c\u3092\u51e6\u7406\u3059\u308b\u306e\u3092\u5fd8\u308c\u305f\u306e\u304b\u3001\u305d\u308c\u3068\u3082\u610f\u56f3\u7684\u306b\u51e6\u7406\u3057\u305f\u306e\u304b\u3092\u77e5\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u3067\u3057\u3087\u3046\u304b\u3002
\u3053\u308c\u3089\u306e\u7406\u7531\u306b\u3088\u308a\u3001\u30a8\u30e9\u30fc\u3092\u7121\u8996\u3057\u305f\u3044\u5834\u5408\u3001\u30d6\u30e9\u30f3\u30af\u8b58\u5225\u5b50\uff08 _
\uff09\u3092\u4f7f\u3046\u307b\u304b\u3042\u308a\u307e\u305b\u3093\u3002
_ = notify\n
\u30b3\u30f3\u30d1\u30a4\u30eb\u3068\u5b9f\u884c\u6642\u9593\u306e\u70b9\u3067\u306f\u3001\u3053\u306e\u65b9\u6cd5\u306f\u6700\u521d\u306e\u30b3\u30fc\u30c9\u90e8\u5206\u3068\u6bd4\u3079\u3066\u4f55\u3082\u5909\u308f\u308a\u307e\u305b\u3093\u3002\u3057\u304b\u3057\u3001\u3053\u306e\u65b0\u3057\u3044\u30d0\u30fc\u30b8\u30e7\u30f3\u3067\u306f\u3001\u79c1\u305f\u3061\u304c\u30a8\u30e9\u30fc\u306b\u95a2\u5fc3\u304c\u306a\u3044\u3053\u3068\u3092\u660e\u3089\u304b\u306b\u3057\u3066\u3044\u307e\u3059\u3002\u307e\u305f\u3001\u30a8\u30e9\u30fc\u304c\u7121\u8996\u3055\u308c\u308b\u7406\u7531\u3092\u793a\u3059\u30b3\u30e1\u30f3\u30c8\u3092\u8ffd\u52a0\u3059\u308b\u3053\u3068\u3082\u3067\u304d\u307e\u3059\u3002
// \u6700\u5927\u3067\u3082 1 \u56de\u306e\u4f1d\u9054 \n// \u305d\u308c\u3086\u3048\u3001\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u305f\u5834\u5408\u306b\u305d\u308c\u3089\u306e\u4e00\u90e8\u304c\u5931\u308f\u308c\u308b\u3053\u3068\u306f\u8a31\u5bb9\u3055\u308c\u307e\u3059\n_ = notify()\n
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#_9","title":"\u4e26\u884c\u51e6\u7406\uff1a\u57fa\u790e","text":""},{"location":"ja/#55","title":"\u4e26\u884c\u51e6\u7406\u3068\u4e26\u5217\u51e6\u7406\u306e\u6df7\u540c (#55)","text":"\u8981\u7d04\u4e26\u884c\u51e6\u7406\u3068\u4e26\u5217\u51e6\u7406\u306e\u57fa\u672c\u7684\u306a\u9055\u3044\u3092\u7406\u89e3\u3059\u308b\u3053\u3068\u306f\u3001 Go \u958b\u767a\u8005\u306b\u3068\u3063\u3066\u5fc5\u9808\u3067\u3059\u3002\u4e26\u884c\u51e6\u7406\u306f\u69cb\u9020\u306b\u95a2\u3059\u308b\u3082\u306e\u3067\u3059\u304c\u3001\u4e26\u5217\u51e6\u7406\u306f\u5b9f\u884c\u306b\u95a2\u3059\u308b\u3082\u306e\u3067\u3059\u3002
\u4e26\u884c\u51e6\u7406\u3068\u4e26\u5217\u51e6\u7406\u306f\u540c\u3058\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u3002
\u307e\u3068\u3081\u308b\u3068\u3001\u4e26\u884c\u51e6\u7406\u306f\u3001\u4e26\u5217\u5316\u3067\u304d\u308b\u90e8\u5206\u3092\u3082\u3064\u554f\u984c\u3092\u89e3\u6c7a\u3059\u308b\u305f\u3081\u306e\u69cb\u9020\u3092\u63d0\u4f9b\u3057\u307e\u3059\u3002\u3059\u306a\u308f\u3061\u3001\u4e26\u884c\u51e6\u7406\u306b\u3088\u308a\u4e26\u5217\u51e6\u7406\u304c\u53ef\u80fd \u306b\u306a\u308a\u307e\u3059 \u3002
"},{"location":"ja/#56","title":"\u4e26\u884c\u51e6\u7406\u306e\u307b\u3046\u304c\u5e38\u306b\u65e9\u3044\u3068\u8003\u3048\u3066\u3044\u308b (#56)","text":"\u8981\u7d04\u719f\u7df4\u3057\u305f\u958b\u767a\u8005\u306b\u306a\u308b\u306b\u306f\u3001\u4e26\u884c\u51e6\u7406\u304c\u5fc5\u305a\u3057\u3082\u9ad8\u901f\u3067\u3042\u308b\u3068\u306f\u9650\u3089\u306a\u3044\u3053\u3068\u3092\u8a8d\u8b58\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u6700\u5c0f\u9650\u306e\u30ef\u30fc\u30af\u30ed\u30fc\u30c9\u306e\u4e26\u5217\u51e6\u7406\u3092\u4f34\u3046\u89e3\u6c7a\u7b56\u306f\u3001\u5fc5\u305a\u3057\u3082\u9010\u6b21\u51e6\u7406\u3088\u308a\u9ad8\u901f\u3067\u3042\u308b\u3068\u306f\u9650\u308a\u307e\u305b\u3093\u3002\u9010\u6b21\u51e6\u7406\u3068\u4e26\u884c\u51e6\u7406\u306e\u30d9\u30f3\u30c1\u30de\u30fc\u30af\u306f\u3001\u4eee\u5b9a\u3092\u691c\u8a3c\u3059\u308b\u65b9\u6cd5\u3067\u3042\u308b\u3079\u304d\u3067\u3059\u3002
\u30bb\u30af\u30b7\u30e7\u30f3\u5168\u6587\u306f\u3053\u3061\u3089\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#57","title":"\u30c1\u30e3\u30cd\u30eb\u307e\u305f\u306f\u30df\u30e5\u30fc\u30c6\u30c3\u30af\u30b9\u3092\u3044\u3064\u4f7f\u7528\u3059\u308b\u3079\u304d\u304b\u306b\u3064\u3044\u3066\u6238\u60d1\u3063\u3066\u3044\u308b (#57)","text":"\u8981\u7d04\u30b4\u30eb\u30fc\u30c1\u30f3\u306e\u76f8\u4e92\u4f5c\u7528\u3092\u8a8d\u8b58\u3057\u3066\u3044\u308b\u3053\u3068\u306f\u3001\u30c1\u30e3\u30cd\u30eb\u3068\u30df\u30e5\u30fc\u30c6\u30c3\u30af\u30b9\u306e\u3069\u3061\u3089\u3092\u9078\u629e\u3059\u308b\u304b\u3092\u6c7a\u5b9a\u3059\u308b\u3068\u304d\u306b\u3082\u5f79\u7acb\u3061\u307e\u3059\u3002\u4e00\u822c\u306b\u3001\u4e26\u5217\u30b4\u30eb\u30fc\u30c1\u30f3\u306b\u306f\u540c\u671f\u304c\u5fc5\u8981\u3067\u3042\u308a\u3001\u3057\u305f\u304c\u3063\u3066\u30df\u30e5\u30fc\u30c6\u30c3\u30af\u30b9\u304c\u5fc5\u8981\u3067\u3059\u3002\u53cd\u5bfe\u306b\u3001\u4e26\u884c\u30b4\u30eb\u30fc\u30c1\u30f3\u306f\u901a\u5e38\u3001\u8abf\u6574\u3068\u30aa\u30fc\u30b1\u30b9\u30c8\u30ec\u30fc\u30b7\u30e7\u30f3\u3001\u3064\u307e\u308a\u30c1\u30e3\u30cd\u30eb\u3092\u5fc5\u8981\u3068\u3057\u307e\u3059\u3002
\u4e26\u884c\u51e6\u7406\u306e\u554f\u984c\u3092\u8003\u616e\u3059\u308b\u3068\u3001\u30c1\u30e3\u30cd\u30eb\u307e\u305f\u306f\u30df\u30e5\u30fc\u30c6\u30c3\u30af\u30b9\u3092\u4f7f\u7528\u3057\u305f\u89e3\u6c7a\u7b56\u3092\u5b9f\u88c5\u3067\u304d\u308b\u304b\u3069\u3046\u304b\u304c\u5fc5\u305a\u3057\u3082\u660e\u78ba\u3067\u306f\u306a\u3044\u53ef\u80fd\u6027\u304c\u3042\u308a\u307e\u3059\u3002Go\u8a00\u8a9e\u306f\u901a\u4fe1\u306b\u3088\u308b\u30e1\u30e2\u30ea\u306e\u5171\u6709\u3092\u4fc3\u9032\u3059\u308b\u305f\u3081\u3001\u8d77\u3053\u308a\u3046\u308b\u9593\u9055\u3044\u306e\u3046\u3061\u306e\u4e00\u3064\u306f\u3001\u30e6\u30fc\u30b9\u30b1\u30fc\u30b9\u306b\u304b\u304b\u308f\u3089\u305a\u3001\u30c1\u30e3\u30cd\u30eb\u306e\u4f7f\u7528\u3092\u5e38\u306b\u5f37\u5236\u3059\u308b\u3053\u3068\u3067\u3059\u3002\u3057\u304b\u3057\u306a\u304c\u3089\u30012 \u3064\u306e\u65b9\u6cd5\u306f\u88dc\u5b8c\u7684\u306a\u3082\u306e\u3067\u3042\u308b\u3068\u898b\u306a\u3059\u3079\u304d\u3067\u3059\u3002
\u30c1\u30e3\u30cd\u30eb\u307e\u305f\u306f\u30df\u30e5\u30fc\u30c6\u30c3\u30af\u30b9\u306f\u3069\u306e\u3088\u3046\u306a\u5834\u5408\u306b\u4f7f\u7528\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u306e\u3067\u3057\u3087\u3046\u304b\u3002\u6b21\u306e\u56f3\u306e\u4f8b\u3092\u30d0\u30c3\u30af\u30dc\u30fc\u30f3\u3068\u3057\u3066\u4f7f\u7528\u3057\u307e\u3059\u3002\u3053\u306e\u4f8b\u306b\u306f\u3001\u7279\u5b9a\u306e\u95a2\u4fc2\u3092\u6301\u3064 3 \u3064\u306e\u7570\u306a\u308b\u30b4\u30eb\u30fc\u30c1\u30f3\u304c\u3042\u308a\u307e\u3059\u3002
\u539f\u5247\u3068\u3057\u3066\u3001\u4e26\u5217\u30b4\u30eb\u30fc\u30c1\u30f3\u306f\u3001\u30b9\u30e9\u30a4\u30b9\u306a\u3069\u306e\u5171\u6709\u30ea\u30bd\u30fc\u30b9\u306b\u30a2\u30af\u30bb\u30b9\u3057\u305f\u308a\u5909\u66f4\u3057\u305f\u308a\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u5834\u5408\u306a\u3069\u306b\u3001_\u540c\u671f_\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u540c\u671f\u306f\u30df\u30e5\u30fc\u30c6\u30c3\u30af\u30b9\u3067\u306f\u5f37\u5236\u3055\u308c\u307e\u3059\u304c\u3001\u3069\u306e\u30c1\u30e3\u30cd\u30eb\u578b\u3067\u3082\u5f37\u5236\u3055\u308c\u307e\u305b\u3093\uff08\u30d0\u30c3\u30d5\u30a1\u3042\u308a\u30c1\u30e3\u30cd\u30eb\u3092\u9664\u304f\uff09\u3002\u3057\u305f\u304c\u3063\u3066\u3001\u4e00\u822c\u306b\u3001\u4e26\u5217\u30b4\u30eb\u30fc\u30c1\u30f3\u9593\u306e\u540c\u671f\u306f\u30df\u30e5\u30fc\u30c6\u30c3\u30af\u30b9\u3092\u4ecb\u3057\u3066\u9054\u6210\u3055\u308c\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002
\u4e00\u65b9\u3001\u4e00\u822c\u306b\u3001\u4e26\u884c\u30b4\u30eb\u30fc\u30c1\u30f3\u306f \u8abf\u6574\u304a\u3088\u3073\u30aa\u30fc\u30b1\u30b9\u30c8\u30ec\u30fc\u30b7\u30e7\u30f3 \u3092\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u305f\u3068\u3048\u3070\u3001G3 \u304c G1 \u3068 G2 \u306e\u4e21\u65b9\u304b\u3089\u306e\u7d50\u679c\u3092\u96c6\u7d04\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u5834\u5408\u3001G1 \u3068 G2 \u306f\u65b0\u3057\u3044\u4e2d\u9593\u7d50\u679c\u304c\u5229\u7528\u53ef\u80fd\u3067\u3042\u308b\u3053\u3068\u3092 G3 \u306b\u901a\u77e5\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u3053\u306e\u8abf\u6574\u306f\u30b3\u30df\u30e5\u30cb\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u7bc4\u56f2\u3001\u3064\u307e\u308a\u30c1\u30e3\u30cd\u30eb\u306b\u8a72\u5f53\u3057\u307e\u3059\u3002
\u4e26\u884c\u30b4\u30eb\u30fc\u30c1\u30f3\u306b\u95a2\u3057\u3066\u306f\u3001\u30ea\u30bd\u30fc\u30b9\u306e\u6240\u6709\u6a29\u3092\u3042\u308b\u30b9\u30c6\u30c3\u30d7\uff08G1 \u304a\u3088\u3073 G2\uff09\u304b\u3089\u5225\u306e\u30b9\u30c6\u30c3\u30d7\uff08G3\uff09\u306b\u79fb\u7ba1\u3057\u305f\u3044\u5834\u5408\u3082\u3042\u308a\u307e\u3059\u3002\u305f\u3068\u3048\u3070\u3001G1 \u3068 G2 \u306b\u3088\u3063\u3066\u5171\u6709\u30ea\u30bd\u30fc\u30b9\u304c\u8c4a\u304b\u306b\u306a\u3063\u3066\u3044\u308b\u5834\u5408\u3001\u3042\u308b\u6642\u70b9\u3067\u3053\u306e\u30b8\u30e7\u30d6\u306f\u5b8c\u4e86\u3057\u305f\u3068\u898b\u306a\u3055\u308c\u307e\u3059\u3002\u3053\u3053\u3067\u306f\u3001\u30c1\u30e3\u30cd\u30eb\u3092\u4f7f\u7528\u3057\u3066\u3001\u7279\u5b9a\u306e\u30ea\u30bd\u30fc\u30b9\u306e\u6e96\u5099\u304c\u3067\u304d\u3066\u3044\u308b\u3053\u3068\u3092\u901a\u77e5\u3057\u3001\u6240\u6709\u6a29\u306e\u79fb\u8ee2\u3092\u51e6\u7406\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002
\u30df\u30e5\u30fc\u30c6\u30c3\u30af\u30b9\u3068\u30c1\u30e3\u30cd\u30eb\u306b\u306f\u7570\u306a\u308b\u30bb\u30de\u30f3\u30c6\u30a3\u30af\u30b9\u304c\u3042\u308a\u307e\u3059\u3002\u30b9\u30c6\u30fc\u30c8\u3092\u5171\u6709\u3057\u305f\u3044\u3068\u304d\u3001\u307e\u305f\u306f\u5171\u6709\u30ea\u30bd\u30fc\u30b9\u306b\u30a2\u30af\u30bb\u30b9\u3057\u305f\u3044\u3068\u304d\u306f\u3001\u30df\u30e5\u30fc\u30c6\u30c3\u30af\u30b9\u306b\u3088\u3063\u3066\u3053\u306e\u30ea\u30bd\u30fc\u30b9\u3078\u306e\u6392\u4ed6\u7684\u30a2\u30af\u30bb\u30b9\u304c\u4fdd\u8a3c\u3055\u308c\u307e\u3059\u3002\u53cd\u5bfe\u306b\u3001\u30c1\u30e3\u30cd\u30eb\u306f\u30c7\u30fc\u30bf\u306e\u6709\u7121\uff08chan struct{}
\u306e\u6709\u7121\uff09\u306b\u95a2\u4fc2\u306a\u304f\u30b7\u30b0\u30ca\u30eb\u3092\u884c\u3046\u4ed5\u7d44\u307f\u3067\u3059\u3002\u8abf\u6574\u3084\u6240\u6709\u6a29\u306e\u79fb\u8ee2\u306f\u30c1\u30e3\u30cd\u30eb\u3092\u901a\u3058\u3066\u884c\u3046\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u30b4\u30eb\u30fc\u30c1\u30f3\u304c\u4e26\u5217\u304b\u4e26\u884c\u304b\u3092\u77e5\u308b\u3053\u3068\u304c\u91cd\u8981\u3067\u3059\u3002\u4e00\u822c\u306b\u3001\u4e26\u5217\u30b4\u30eb\u30fc\u30c1\u30f3\u306b\u306f\u30df\u30e5\u30fc\u30c6\u30c3\u30af\u30b9\u304c\u5fc5\u8981\u3067\u3001\u4e26\u884c\u30b4\u30eb\u30fc\u30c1\u30f3\u306b\u306f\u30c1\u30e3\u30cd\u30eb\u304c\u5fc5\u8981\u3067\u3059\u3002
\u4e26\u884c\u51e6\u7406\u306b\u719f\u9054\u3059\u308b\u3068\u3044\u3046\u3053\u3068\u306f\u3001\u30c7\u30fc\u30bf\u7af6\u5408\u3068\u7af6\u5408\u72b6\u614b\u304c\u7570\u306a\u308b\u6982\u5ff5\u3067\u3042\u308b\u3053\u3068\u3092\u7406\u89e3\u3059\u308b\u3053\u3068\u3082\u610f\u5473\u3057\u307e\u3059\u3002\u30c7\u30fc\u30bf\u7af6\u5408\u306f\u3001\u8907\u6570\u306e\u30b4\u30eb\u30fc\u30c1\u30f3\u304c\u540c\u3058\u30e1\u30e2\u30ea\u4f4d\u7f6e\u306b\u540c\u6642\u306b\u30a2\u30af\u30bb\u30b9\u3057\u3001\u305d\u306e\u3046\u3061\u306e\u5c11\u306a\u304f\u3068\u3082 1 \u3064\u304c\u66f8\u304d\u8fbc\u307f\u3092\u884c\u3063\u3066\u3044\u308b\u5834\u5408\u306b\u767a\u751f\u3057\u307e\u3059\u3002\u4e00\u65b9\u3001\u30c7\u30fc\u30bf\u7af6\u5408\u304c\u306a\u3044\u3053\u3068\u304c\u5fc5\u305a\u3057\u3082\u6c7a\u5b9a\u7684\u5b9f\u884c\u3092\u610f\u5473\u3059\u308b\u308f\u3051\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u3002\u52d5\u4f5c\u304c\u5236\u5fa1\u3067\u304d\u306a\u3044\u30a4\u30d9\u30f3\u30c8\u306e\u9806\u5e8f\u3084\u30bf\u30a4\u30df\u30f3\u30b0\u306b\u4f9d\u5b58\u3057\u3066\u3044\u308b\u5834\u5408\u3001\u3053\u308c\u306f\u7af6\u5408\u72b6\u614b\u3067\u3059\u3002
\u7af6\u5408\u554f\u984c\u306f\u3001\u30d7\u30ed\u30b0\u30e9\u30de\u30fc\u304c\u76f4\u9762\u3059\u308b\u53ef\u80fd\u6027\u306e\u3042\u308b\u30d0\u30b0\u306e\u4e2d\u3067\u6700\u3082\u56f0\u96e3\u304b\u3064\u6700\u3082\u6f5c\u4f0f\u6027\u306e\u9ad8\u3044\u30d0\u30b0\u306e 1 \u3064\u3068\u306a\u308a\u307e\u3059\u3002Go \u958b\u767a\u8005\u3068\u3057\u3066\u3001\u79c1\u305f\u3061\u306f\u30c7\u30fc\u30bf\u7af6\u5408\u3068\u7af6\u5408\u72b6\u614b\u3001\u305d\u308c\u3089\u304c\u53ca\u307c\u3057\u3046\u308b\u5f71\u97ff\u3001\u304a\u3088\u3073\u305d\u308c\u3089\u3092\u56de\u907f\u3059\u308b\u65b9\u6cd5\u306a\u3069\u306e\u91cd\u8981\u306a\u5074\u9762\u3092\u7406\u89e3\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002
"},{"location":"ja/#_10","title":"\u30c7\u30fc\u30bf\u7af6\u5408","text":"\u30c7\u30fc\u30bf\u7af6\u5408\u306f\u30012 \u3064\u4ee5\u4e0a\u306e\u30b4\u30eb\u30fc\u30c1\u30f3\u304c\u540c\u3058\u30e1\u30e2\u30ea\u4f4d\u7f6e\u306b\u540c\u6642\u306b\u30a2\u30af\u30bb\u30b9\u3057\u3001\u5c11\u306a\u304f\u3068\u3082 1 \u3064\u304c\u66f8\u304d\u8fbc\u307f\u3092\u884c\u3063\u3066\u3044\u308b\u5834\u5408\u306b\u767a\u751f\u3057\u307e\u3059\u3002\u3053\u306e\u5834\u5408\u3001\u5371\u967a\u306a\u7d50\u679c\u304c\u751f\u3058\u308b\u53ef\u80fd\u6027\u304c\u3042\u308a\u307e\u3059\u3002\u3055\u3089\u306b\u60aa\u3044\u3053\u3068\u306b\u3001\u72b6\u6cc1\u306b\u3088\u3063\u3066\u306f\u3001\u30e1\u30e2\u30ea\u4f4d\u7f6e\u306b\u7121\u610f\u5473\u306a\u30d3\u30c3\u30c8\u306e\u7d44\u307f\u5408\u308f\u305b\u3092\u542b\u3080\u5024\u304c\u4fdd\u6301\u3055\u308c\u3066\u3057\u307e\u3046\u53ef\u80fd\u6027\u304c\u3042\u308a\u307e\u3059\u3002
\u3055\u307e\u3056\u307e\u306a\u624b\u6cd5\u3092\u99c6\u4f7f\u3057\u3066\u3001\u30c7\u30fc\u30bf\u7af6\u5408\u306e\u767a\u751f\u3092\u9632\u3050\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u305f\u3068\u3048\u3070
sync/atomic
\u30d1\u30c3\u30b1\u30fc\u30b8\u3092\u4f7f\u7528\u3059\u308b \u5b9f\u884c\u3057\u305f\u3044\u64cd\u4f5c\u306b\u5fdc\u3058\u3066\u3001\u30c7\u30fc\u30bf\u7af6\u5408\u306e\u306a\u3044\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u304c\u5fc5\u305a\u3057\u3082\u6c7a\u5b9a\u7684\u306a\u7d50\u679c\u3092\u610f\u5473\u3059\u308b\u3067\u3057\u3087\u3046\u304b\u3002\u305d\u3046\u3068\u306f\u3044\u3048\u307e\u305b\u3093\u3002
\u7af6\u5408\u72b6\u614b\u306f\u3001\u52d5\u4f5c\u304c\u5236\u5fa1\u3067\u304d\u306a\u3044\u30a4\u30d9\u30f3\u30c8\u306e\u30b7\u30fc\u30b1\u30f3\u30b9\u307e\u305f\u306f\u30bf\u30a4\u30df\u30f3\u30b0\u306b\u4f9d\u5b58\u3059\u308b\u5834\u5408\u306b\u767a\u751f\u3057\u307e\u3059\u3002\u3053\u3053\u3067\u306f\u3001\u30a4\u30d9\u30f3\u30c8\u306e\u30bf\u30a4\u30df\u30f3\u30b0\u304c\u30b4\u30eb\u30fc\u30c1\u30f3\u306e\u5b9f\u884c\u9806\u5e8f\u3067\u3059\u3002
\u307e\u3068\u3081\u308b\u3068\u3001\u4e26\u884c\u51e6\u7406\u306e\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3067\u4f5c\u696d\u3059\u308b\u5834\u5408\u3001\u30c7\u30fc\u30bf\u7af6\u5408\u306f\u7af6\u5408\u72b6\u614b\u3068\u306f\u7570\u306a\u308b\u3053\u3068\u3092\u7406\u89e3\u3059\u308b\u3053\u3068\u304c\u4e0d\u53ef\u6b20\u3067\u3059\u3002\u30c7\u30fc\u30bf\u7af6\u5408\u306f\u3001\u8907\u6570\u306e\u30b4\u30eb\u30fc\u30c1\u30f3\u304c\u540c\u3058\u30e1\u30e2\u30ea\u4f4d\u7f6e\u306b\u540c\u6642\u306b\u30a2\u30af\u30bb\u30b9\u3057\u3001\u305d\u306e\u3046\u3061\u306e\u5c11\u306a\u304f\u3068\u3082 1 \u3064\u304c\u66f8\u304d\u8fbc\u307f\u3092\u884c\u3063\u3066\u3044\u308b\u5834\u5408\u306b\u767a\u751f\u3057\u307e\u3059\u3002\u30c7\u30fc\u30bf\u7af6\u5408\u3068\u306f\u3001\u4e88\u60f3\u5916\u306e\u52d5\u4f5c\u3092\u610f\u5473\u3057\u307e\u3059\u3002\u305f\u3060\u3057\u3001\u30c7\u30fc\u30bf\u7af6\u5408\u306e\u306a\u3044\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u304c\u5fc5\u305a\u3057\u3082\u6c7a\u5b9a\u7684\u306a\u7d50\u679c\u3092\u610f\u5473\u3059\u308b\u308f\u3051\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u3002\u30c7\u30fc\u30bf\u7af6\u5408\u304c\u306a\u304f\u3066\u3082\u3001\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306f\u5236\u5fa1\u3055\u308c\u3066\u3044\u306a\u3044\u30a4\u30d9\u30f3\u30c8\uff08\u30b4\u30eb\u30fc\u30c1\u30f3\u306e\u5b9f\u884c\u3001\u30c1\u30e3\u30cd\u30eb\u3078\u306e\u30e1\u30c3\u30bb\u30fc\u30b8\u306e\u767a\u4fe1\u901f\u5ea6\u3001\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3078\u306e\u547c\u3073\u51fa\u3057\u306e\u7d99\u7d9a\u6642\u9593\u306a\u3069\uff09\u306b\u4f9d\u5b58\u3059\u308b\u6319\u52d5\u3092\u6301\u3064\u3053\u3068\u304c\u3042\u308a\u307e\u3059\u3002\u305d\u306e\u5834\u5408\u306f\u7af6\u5408\u72b6\u614b\u3067\u3059\u3002\u4e26\u884c\u51e6\u7406\u306e\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u8a2d\u8a08\u306b\u719f\u7df4\u3059\u308b\u306b\u306f\u3001\u4e21\u65b9\u306e\u6982\u5ff5\u3092\u7406\u89e3\u3059\u308b\u3053\u3068\u304c\u809d\u8981\u3067\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#59","title":"\u30ef\u30fc\u30af\u30ed\u30fc\u30c9\u30bf\u30a4\u30d7\u3054\u3068\u306e\u4e26\u884c\u51e6\u7406\u306e\u5f71\u97ff\u3092\u7406\u89e3\u3057\u3066\u3044\u306a\u3044 (#59)","text":"\u8981\u7d04\u4e00\u5b9a\u6570\u306e\u30b4\u30eb\u30fc\u30c1\u30f3\u3092\u4f5c\u6210\u3059\u308b\u3068\u304d\u306f\u3001\u30ef\u30fc\u30af\u30ed\u30fc\u30c9\u306e\u30bf\u30a4\u30d7\u3092\u8003\u616e\u3057\u3066\u304f\u3060\u3055\u3044\u3002CPU \u30d0\u30a6\u30f3\u30c9\u306e\u30b4\u30eb\u30fc\u30c1\u30f3\u3092\u4f5c\u6210\u3059\u308b\u3068\u3044\u3046\u3053\u3068\u306f\u3001\u3053\u306e\u6570\u3092 GOMAXPROCS
\u5909\u6570\uff08\u30c7\u30d5\u30a9\u30eb\u30c8\u3067\u306f\u30db\u30b9\u30c8\u4e0a\u306e CPU \u30b3\u30a2\u306e\u6570\u306b\u57fa\u3065\u304f\uff09\u306b\u8fd1\u3065\u3051\u308b\u3053\u3068\u3092\u610f\u5473\u3057\u307e\u3059\u3002I/O \u30d0\u30a6\u30f3\u30c9\u306e\u30b4\u30eb\u30fc\u30c1\u30f3\u306e\u4f5c\u6210\u306f\u3001\u5916\u90e8\u30b7\u30b9\u30c6\u30e0\u306a\u3069\u306e\u4ed6\u306e\u8981\u56e0\u306b\u4f9d\u5b58\u3057\u307e\u3059\u3002
\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u3067\u306f\u3001\u30ef\u30fc\u30af\u30ed\u30fc\u30c9\u306e\u5b9f\u884c\u6642\u9593\u306f\u6b21\u306e\u3044\u305a\u308c\u304b\u306b\u3088\u3063\u3066\u5236\u9650\u3055\u308c\u307e\u3059\u3002
\u3053\u3053\u6570\u5341\u5e74\u3067\u30e1\u30e2\u30ea\u304c\u975e\u5e38\u306b\u5b89\u4fa1\u306b\u306a\u3063\u305f\u3053\u3068\u3092\u8003\u616e\u3059\u308b\u3068\u3001 3 \u3064\u76ee\u306f\u73fe\u5728\u3067\u306f\u6700\u3082\u307e\u308c\u3067\u3059\u3002\u3057\u305f\u304c\u3063\u3066\u3001\u3053\u306e\u30bb\u30af\u30b7\u30e7\u30f3\u3067\u306f\u3001\u6700\u521d\u306e 2 \u3064\u306e\u30ef\u30fc\u30af\u30ed\u30fc\u30c9\u30bf\u30a4\u30d7\u3001CPU \u30d0\u30a6\u30f3\u30c9\u3068 I/O \u30d0\u30a6\u30f3\u30c9\u306b\u7126\u70b9\u3092\u5f53\u3066\u307e\u3059\u3002
\u30ef\u30fc\u30ab\u30fc\u306b\u3088\u3063\u3066\u5b9f\u884c\u3055\u308c\u308b\u30ef\u30fc\u30af\u30ed\u30fc\u30c9\u304c I/O \u30d0\u30a6\u30f3\u30c9\u3067\u3042\u308b\u5834\u5408\u3001\u5024\u306f\u4e3b\u306b\u5916\u90e8\u30b7\u30b9\u30c6\u30e0\u306b\u4f9d\u5b58\u3057\u307e\u3059\u3002\u9006\u306b\u3001\u30ef\u30fc\u30af\u30ed\u30fc\u30c9\u304c CPU \u306b\u4f9d\u5b58\u3057\u3066\u3044\u308b\u5834\u5408\u3001\u30b4\u30eb\u30fc\u30c1\u30f3\u306e\u6700\u9069\u306a\u6570\u306f\u5229\u7528\u53ef\u80fd\u306a CPU \u30b3\u30a2\u306e\u6570\u306b\u8fd1\u304f\u306a\u308a\u307e\u3059\uff08\u30d9\u30b9\u30c8\u30d7\u30e9\u30af\u30c6\u30a3\u30b9\u306f runtime.GOMAXPROCS
\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u3067\u3059\uff09\u3002\u4e26\u884c\u51e6\u7406\u306e\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u8a2d\u8a08\u3059\u308b\u5834\u5408\u3001\u30ef\u30fc\u30af\u30ed\u30fc\u30c9\u306e\u30bf\u30a4\u30d7\uff08 I/O \u3042\u308b\u3044\u306f CPU \uff09\u3092\u77e5\u308b\u3053\u3068\u304c\u91cd\u8981\u3067\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#go-context-60","title":"Go Context \u306b\u5bfe\u3059\u308b\u8aa4\u89e3 (#60)","text":"\u8981\u7d04Go Context \u306f\u3001Go\u8a00\u8a9e\u306e\u4e26\u884c\u51e6\u7406\u306e\u57fa\u790e\u306e\u4e00\u90e8\u3067\u3082\u3042\u308a\u307e\u3059\u3002 Context \u3092\u4f7f\u7528\u3059\u308b\u3068\u3001\u30c7\u30c3\u30c9\u30e9\u30a4\u30f3\u3001\u30ad\u30fc\u3068\u5024\u306e\u30ea\u30b9\u30c8\u3092\u4fdd\u6301\u3067\u304d\u307e\u3059\u3002
https://pkg.go.dev/context
Context \u306f\u3001\u30c7\u30c3\u30c9\u30e9\u30a4\u30f3\u3001\u30ad\u30e3\u30f3\u30bb\u30eb\u30b7\u30b0\u30ca\u30eb\u3001\u305d\u306e\u4ed6\u306e\u5024\u3092 API \u306e\u5883\u754c\u3092\u8d8a\u3048\u3066\u4f1d\u9054\u3057\u307e\u3059\u3002
"},{"location":"ja/#_12","title":"\u30c7\u30c3\u30c9\u30e9\u30a4\u30f3","text":"\u30c7\u30c3\u30c9\u30e9\u30a4\u30f3\u3068\u306f\u3001\u6b21\u306e\u3044\u305a\u308c\u304b\u3067\u6c7a\u5b9a\u3055\u308c\u308b\u7279\u5b9a\u306e\u6642\u70b9\u3092\u6307\u3057\u307e\u3059\u3002
time.Duration
\uff08\u4f8b\uff1a250 ms\uff09time.Time
\uff08\u4f8b\uff1a2023-02-07 00:00:00 UTC\uff09 \u30c7\u30c3\u30c9\u30e9\u30a4\u30f3\u306e\u30bb\u30de\u30f3\u30c6\u30a3\u30af\u30b9\u306f\u3001\u3053\u308c\u3092\u904e\u304e\u305f\u5834\u5408\u306f\u9032\u884c\u4e2d\u306e\u30a2\u30af\u30c6\u30a3\u30d3\u30c6\u30a3\u3092\u505c\u6b62\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u3053\u3068\u3092\u4f1d\u3048\u307e\u3059\u3002\u30a2\u30af\u30c6\u30a3\u30d3\u30c6\u30a3\u3068\u306f\u3001\u305f\u3068\u3048\u3070\u3001\u30c1\u30e3\u30cd\u30eb\u304b\u3089\u306e\u30e1\u30c3\u30bb\u30fc\u30b8\u306e\u53d7\u4fe1\u3092\u5f85\u6a5f\u3057\u3066\u3044\u308b I/O \u30ea\u30af\u30a8\u30b9\u30c8\u3084\u30b4\u30eb\u30fc\u30c1\u30f3\u3067\u3059\u3002
"},{"location":"ja/#_13","title":"\u30ad\u30e3\u30f3\u30bb\u30eb\u30b7\u30b0\u30ca\u30eb","text":"Go Context \u306e\u3082\u3046 1 \u3064\u306e\u4f7f\u7528\u4f8b\u306f\u3001\u30ad\u30e3\u30f3\u30bb\u30eb\u30b7\u30b0\u30ca\u30eb\u3092\u4f1d\u9001\u3059\u308b\u3053\u3068\u3067\u3059\u3002\u5225\u306e\u30b4\u30eb\u30fc\u30c1\u30f3\u5185\u3067 CreateFileWatcher(ctx context.Context, filename string)
\u3092\u547c\u3073\u51fa\u3059\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u4f5c\u6210\u3059\u308b\u3053\u3068\u3092\u60f3\u50cf\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002\u3053\u306e\u95a2\u6570\u306f\u3001\u30d5\u30a1\u30a4\u30eb\u304b\u3089\u8aad\u307f\u53d6\u308a\u3092\u7d9a\u3051\u3066\u66f4\u65b0\u3092\u30ad\u30e3\u30c3\u30c1\u3059\u308b\u7279\u5b9a\u306e\u30d5\u30a1\u30a4\u30eb\u30a6\u30a9\u30c3\u30c1\u30e3\u30fc\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002\u63d0\u4f9b\u3055\u308c\u305f Context \u304c\u671f\u9650\u5207\u308c\u306b\u306a\u308b\u304b\u30ad\u30e3\u30f3\u30bb\u30eb\u3055\u308c\u308b\u3068\u3001\u3053\u306e\u95a2\u6570\u306f\u305d\u308c\u3092\u51e6\u7406\u3057\u3066\u30d5\u30a1\u30a4\u30eb\u8a18\u8ff0\u5b50\u3092\u9589\u3058\u307e\u3059\u3002
Go Context \u306e\u6700\u5f8c\u306e\u4f7f\u7528\u4f8b\u306f\u3001\u30ad\u30fc\u3068\u5024\u306e\u30ea\u30b9\u30c8\u3092\u904b\u3076\u3053\u3068\u3067\u3059\u3002 Context \u306b\u30ad\u30fc\u3068\u5024\u306e\u30ea\u30b9\u30c8\u3092\u542b\u3081\u308b\u610f\u5473\u306f\u4f55\u3067\u3057\u3087\u3046\u304b\u3002Go Context \u306f\u6c4e\u7528\u7684\u3067\u3042\u308b\u305f\u3081\u3001\u4f7f\u7528\u4f8b\u306f\u7121\u9650\u306b\u3042\u308a\u307e\u3059\u3002
\u305f\u3068\u3048\u3070\u3001\u30c8\u30ec\u30fc\u30b9\u3092\u4f7f\u7528\u3059\u308b\u5834\u5408\u3001\u7570\u306a\u308b\u30b5\u30d6\u95a2\u6570\u306e\u9593\u3067\u540c\u3058\u76f8\u95a2 ID \u3092\u5171\u6709\u3057\u305f\u3044\u3053\u3068\u304c\u3042\u308b\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002\u4e00\u90e8\u306e\u958b\u767a\u8005\u306f\u3001\u3053\u306e ID \u3092\u95a2\u6570\u30b7\u30b0\u30cd\u30c1\u30e3\u306e\u4e00\u90e8\u306b\u3059\u308b\u306b\u306f\u3042\u307e\u308a\u306b\u4fb5\u7565\u7684\u3060\u3068\u8003\u3048\u308b\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002\u3053\u306e\u70b9\u306b\u95a2\u3057\u3066\u3001\u4e0e\u3048\u3089\u308c\u305f Context \u306e\u4e00\u90e8\u3068\u3057\u3066\u305d\u308c\u3092\u542b\u3081\u308b\u3053\u3068\u3092\u6c7a\u5b9a\u3059\u308b\u3053\u3068\u3082\u3067\u304d\u307e\u3059\u3002
"},{"location":"ja/#context","title":"Context \u306e\u30ad\u30e3\u30f3\u30bb\u30eb\u3092\u30ad\u30e3\u30c3\u30c1\u3059\u308b","text":"context.Context
\u30bf\u30a4\u30d7\u306f\u3001\u53d7\u4fe1\u5c02\u7528\u306e\u901a\u77e5\u30c1\u30e3\u30cd\u30eb <-chan struct{}
\u3092\u8fd4\u3059 Done
\u30e1\u30bd\u30c3\u30c9\u3092\u30a8\u30af\u30b9\u30dd\u30fc\u30c8\u3057\u307e\u3059\u3002\u3053\u306e\u30c1\u30e3\u30cd\u30eb\u306f\u3001 Context \u306b\u95a2\u9023\u4ed8\u3051\u3089\u308c\u305f\u4f5c\u696d\u3092\u30ad\u30e3\u30f3\u30bb\u30eb\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u5834\u5408\u306b\u9589\u3058\u3089\u308c\u307e\u3059\u3002\u305f\u3068\u3048\u3070
context.WithCancel
\u3067\u4f5c\u6210\u3055\u308c\u305f Context \u306b\u95a2\u9023\u3059\u308b Done \u30c1\u30e3\u30cd\u30eb\u306f\u3001cancel\u95a2\u6570\u304c\u547c\u3073\u51fa\u3055\u308c\u308b\u3068\u9589\u3058\u3089\u308c\u307e\u3059\u3002 context.WithDeadline
\u3067\u4f5c\u6210\u3057\u305f Context \u306b\u95a2\u9023\u3059\u308b Done \u30c1\u30e3\u30cd\u30eb\u306f\u3001\u30c7\u30c3\u30c9\u30e9\u30a4\u30f3\u3092\u904e\u304e\u308b\u3068\u9589\u3058\u3089\u308c\u307e\u3059\u3002 \u6ce8\u610f\u3059\u3079\u304d\u70b9\u306e 1 \u3064\u306f\u3001\u5185\u90e8\u30c1\u30e3\u30cd\u30eb\u306f\u3001\u7279\u5b9a\u306e\u5024\u3092\u53d7\u3051\u53d6\u3063\u305f\u3068\u304d\u3067\u306f\u306a\u304f\u3001 Context \u304c\u30ad\u30e3\u30f3\u30bb\u30eb\u3055\u308c\u305f\u3068\u304d\u3001\u307e\u305f\u306f\u30c7\u30c3\u30c9\u30e9\u30a4\u30f3\u306b\u9054\u3057\u305f\u3068\u304d\u306b\u9589\u3058\u308b\u5fc5\u8981\u304c\u3042\u308b\u3068\u3044\u3046\u3053\u3068\u3067\u3059\u3002\u30c1\u30e3\u30cd\u30eb\u306e\u30af\u30ed\u30fc\u30ba\u306f\u3001\u3059\u3079\u3066\u306e\u6d88\u8cbb\u8005\u30b4\u30eb\u30fc\u30c1\u30f3\u304c\u53d7\u3051\u53d6\u308b\u552f\u4e00\u306e\u30c1\u30e3\u30cd\u30eb\u30a2\u30af\u30b7\u30e7\u30f3\u3067\u3042\u308b\u305f\u3081\u3067\u3059\u3002\u3053\u306e\u3088\u3046\u306b\u3057\u3066\u3001 Context \u304c\u30ad\u30e3\u30f3\u30bb\u30eb\u3055\u308c\u308b\u304b\u3001\u30c7\u30c3\u30c9\u30e9\u30a4\u30f3\u306b\u9054\u3059\u308b\u3068\u3001\u3059\u3079\u3066\u306e\u6d88\u8cbb\u8005\u306b\u901a\u77e5\u304c\u5c4a\u304d\u307e\u3059\u3002
\u307e\u3068\u3081\u308b\u3068\u3001\u719f\u7df4\u3057\u305f Go \u958b\u767a\u8005\u306b\u306a\u308b\u306b\u306f\u3001 Context \u3068\u305d\u306e\u4f7f\u7528\u65b9\u6cd5\u306b\u3064\u3044\u3066\u7406\u89e3\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u539f\u5247\u3068\u3057\u3066\u3001\u30e6\u30fc\u30b6\u30fc\u304c\u5f85\u6a5f\u3055\u305b\u3089\u308c\u308b\u95a2\u6570\u306f Context \u3092\u53d6\u5f97\u3059\u308b\u3079\u304d\u3067\u3059\u3002\u3053\u308c\u306b\u3088\u308a\u3001\u4e0a\u6d41\u306e\u547c\u3073\u51fa\u3057\u5143\u304c\u3053\u306e\u95a2\u6570\u3092\u3044\u3064\u547c\u3073\u51fa\u3059\u304b\u3092\u6c7a\u5b9a\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308b\u304b\u3089\u3067\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#_14","title":"\u4e26\u884c\u51e6\u7406\uff1a\u5b9f\u8df5","text":""},{"location":"ja/#context-61","title":"\u4e0d\u9069\u5207\u306a Context \u3092\u5e83\u3081\u3066\u3057\u307e\u3046 (#61)","text":"\u8981\u7d04Context \u3092\u4f1d\u64ad\u3059\u308b\u969b\u306b\u306f\u3001Context \u3092\u30ad\u30e3\u30f3\u30bb\u30eb\u3067\u304d\u308b\u6761\u4ef6\u3092\u7406\u89e3\u3059\u308b\u3053\u3068\u304c\u91cd\u8981\u3067\u3059\u3002\u305f\u3068\u3048\u3070\u3001\u30ec\u30b9\u30dd\u30f3\u30b9\u304c\u9001\u4fe1\u3055\u308c\u305f\u969b\u306b HTTP \u30cf\u30f3\u30c9\u30e9\u304c Context \u3092\u30ad\u30e3\u30f3\u30bb\u30eb\u3059\u308b\u3068\u304d\u306a\u3069\u3067\u3059\u3002
\u591a\u304f\u306e\u72b6\u6cc1\u3067\u306f\u3001Go Context \u3092\u4f1d\u64ad\u3059\u308b\u3053\u3068\u304c\u63a8\u5968\u3055\u308c\u307e\u3059\u3002\u305f\u3060\u3057\u3001Context \u306e\u4f1d\u64ad\u306b\u3088\u3063\u3066\u8efd\u5fae\u306a\u30d0\u30b0\u304c\u767a\u751f\u3057\u3001\u30b5\u30d6\u95a2\u6570\u304c\u6b63\u3057\u304f\u5b9f\u884c\u3055\u308c\u306a\u304f\u306a\u308b\u5834\u5408\u304c\u3042\u308a\u307e\u3059\u3002
\u6b21\u306e\u4f8b\u3092\u8003\u3048\u3066\u307f\u307e\u3057\u3087\u3046\u3002\u3044\u304f\u3064\u304b\u306e\u30bf\u30b9\u30af\u3092\u5b9f\u884c\u3057\u3066\u30ec\u30b9\u30dd\u30f3\u30b9\u3092\u8fd4\u3059 HTTP \u30cf\u30f3\u30c9\u30e9\u3092\u516c\u958b\u3057\u307e\u3059\u3002\u305f\u3060\u3057\u3001\u30ec\u30b9\u30dd\u30f3\u30b9\u3092\u8fd4\u3059\u76f4\u524d\u306b\u3001\u305d\u308c\u3092 Kafka \u30c8\u30d4\u30c3\u30af\u306b\u9001\u4fe1\u3057\u305f\u3044\u3068\u601d\u3063\u3066\u3044\u307e\u3059\u3002HTTP \u30b3\u30f3\u30b7\u30e5\u30fc\u30de\u306b\u30ec\u30a4\u30c6\u30f3\u30b7\u306e\u70b9\u3067\u30da\u30ca\u30eb\u30c6\u30a3\u3092\u8ab2\u3057\u305f\u304f\u306a\u3044\u306e\u3067\u3001publish \u30a2\u30af\u30b7\u30e7\u30f3\u3092\u65b0\u3057\u3044\u30b4\u30eb\u30fc\u30c1\u30f3\u5185\u3067\u975e\u540c\u671f\u306b\u51e6\u7406\u3057\u305f\u3044\u3068\u8003\u3048\u3066\u3044\u307e\u3059\u3002\u305f\u3068\u3048\u3070\u3001Context \u304c\u30ad\u30e3\u30f3\u30bb\u30eb\u3055\u308c\u305f\u5834\u5408\u306b\u30e1\u30c3\u30bb\u30fc\u30b8\u306e publish \u30a2\u30af\u30b7\u30e7\u30f3\u3092\u4e2d\u65ad\u3067\u304d\u308b\u3088\u3046\u306b\u3001Context \u3092\u53d7\u3051\u5165\u308c\u308b publish
\u95a2\u6570\u3092\u81ea\u7531\u306b\u4f7f\u3048\u308b\u3068\u3057\u307e\u3059\u3002\u53ef\u80fd\u306a\u5b9f\u88c5\u306f\u6b21\u306e\u3068\u304a\u308a\u3067\u3059\u3002
func handler(w http.ResponseWriter, r *http.Request) {\n response, err := doSomeTask(r.Context(), r)\n if err != nil {\n http.Error(w, err.Error(), http.StatusInternalServerError)\n return\n }\n go func() {\n err := publish(r.Context(), response)\n // err \u306e\u51e6\u7406\u3092\u3059\u308b\n }()\n writeResponse(response)\n}\n
\u3053\u306e\u30b3\u30fc\u30c9\u306e\u4f55\u304c\u554f\u984c\u306a\u306e\u3067\u3057\u3087\u3046\u304b\u3002HTTP \u30ea\u30af\u30a8\u30b9\u30c8\u306b\u4ed8\u3055\u308c\u305f Context \u306f\u3001\u3055\u307e\u3056\u307e\u306a\u72b6\u6cc1\u3067\u30ad\u30e3\u30f3\u30bb\u30eb\u3055\u308c\u308b\u53ef\u80fd\u6027\u304c\u3042\u308b\u3053\u3068\u3092\u77e5\u3063\u3066\u304a\u304f\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002
\u6700\u521d\u306e 2 \u3064\u306e\u30b1\u30fc\u30b9\u3067\u306f\u3001\u51e6\u7406\u306f\u304a\u305d\u3089\u304f\u6b63\u3057\u304f\u884c\u308f\u308c\u307e\u3059\u3002\u305f\u3068\u3048\u3070\u3001doSomeTask \u304b\u3089\u30ec\u30b9\u30dd\u30f3\u30b9\u3092\u53d7\u3051\u53d6\u3063\u305f\u3082\u306e\u306e\u3001\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u304c\u63a5\u7d9a\u3092\u9589\u3058\u305f\u5834\u5408\u3001\u30e1\u30c3\u30bb\u30fc\u30b8\u304c publish \u3055\u308c\u306a\u3044\u3088\u3046\u306b\u3001Context \u304c\u65e2\u306b\u30ad\u30e3\u30f3\u30bb\u30eb\u3055\u308c\u305f\u72b6\u614b\u3067 publish \u3092\u547c\u3073\u51fa\u3057\u3066\u3082\u554f\u984c\u306f\u304a\u305d\u3089\u304f\u8d77\u304d\u307e\u305b\u3093\u3002\u3057\u304b\u3057\u3001\u6700\u5f8c\u306e\u30b1\u30fc\u30b9\u306f\u3069\u3046\u3067\u3057\u3087\u3046\u304b\u3002
\u30ec\u30b9\u30dd\u30f3\u30b9\u304c\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u306b\u66f8\u304d\u8fbc\u307e\u308c\u308b\u3068\u3001\u8981\u6c42\u306b\u95a2\u9023\u4ed8\u3051\u3089\u308c\u305f Context \u304c\u30ad\u30e3\u30f3\u30bb\u30eb\u3055\u308c\u307e\u3059\u3002\u3057\u305f\u304c\u3063\u3066\u3001\u7af6\u5408\u72b6\u614b\u306b\u76f4\u9762\u3057\u307e\u3059\u3002
\u5f8c\u8005\u306e\u5834\u5408\u3001HTTP \u30ec\u30b9\u30dd\u30f3\u30b9\u3092\u3059\u3050\u306b\u8fd4\u3059\u306e\u3067\u3001publish \u3092\u547c\u3073\u51fa\u3059\u3068\u30a8\u30e9\u30fc\u304c\u8fd4\u3055\u308c\u307e\u3059\u3002
\u88dc\u8db3Go 1.21 \u304b\u3089\u306f\u3001\u30ad\u30e3\u30f3\u30bb\u30eb\u305b\u305a\u306b\u65b0\u3057\u3044 Context \u3092\u4f5c\u6210\u3059\u308b\u65b9\u6cd5\u304c\u8ffd\u52a0\u3055\u308c\u307e\u3057\u305f\u3002 context.WithoutCancel
\u306f\u3001\u89aa\u304c\u30ad\u30e3\u30f3\u30bb\u30eb\u3055\u308c\u305f\u3068\u304d\u306b\u30ad\u30e3\u30f3\u30bb\u30eb\u3055\u308c\u3066\u3044\u306a\u3044\u89aa\u306e\u30b3\u30d4\u30fc\u3092\u8fd4\u3057\u307e\u3059\u3002
\u307e\u3068\u3081\u308b\u3068\u3001Context \u306e\u4f1d\u64ad\u306f\u614e\u91cd\u306b\u884c\u3046\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#62","title":"\u505c\u6b62\u3059\u3079\u304d\u3068\u304d\u3092\u77e5\u3089\u305a\u306b\u30b4\u30eb\u30fc\u30c1\u30f3\u3092\u958b\u59cb\u3057\u3066\u3057\u307e\u3046 (#62)","text":"\u8981\u7d04\u30ea\u30fc\u30af\u3092\u907f\u3051\u308b\u3053\u3068\u306f\u3001\u30b4\u30eb\u30fc\u30c1\u30f3\u304c\u958b\u59cb\u3055\u308c\u308b\u305f\u3073\u306b\u3001\u6700\u7d42\u7684\u306b\u505c\u6b62\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u3053\u3068\u3092\u610f\u5473\u3057\u307e\u3059\u3002
\u30b4\u30eb\u30fc\u30c1\u30f3\u306f\u7c21\u5358\u306b\u884c\u3046\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u975e\u5e38\u306b\u7c21\u5358\u3067\u3042\u308b\u305f\u3081\u3001\u65b0\u3057\u3044\u30b4\u30eb\u30fc\u30c1\u30f3\u3092\u3044\u3064\u505c\u6b62\u3059\u308b\u304b\u306b\u3064\u3044\u3066\u306e\u8a08\u753b\u3092\u5fc5\u305a\u3057\u3082\u7acb\u3066\u3066\u3044\u306a\u3044\u53ef\u80fd\u6027\u304c\u3042\u308a\u3001\u30ea\u30fc\u30af\u306b\u3064\u306a\u304c\u308b\u3053\u3068\u304c\u3042\u308a\u307e\u3059\u3002\u30b4\u30eb\u30fc\u30c1\u30f3\u3092\u3044\u3064\u505c\u6b62\u3059\u308c\u3070\u3088\u3044\u304b\u308f\u304b\u3089\u306a\u3044\u306e\u306f\u3001Go\u8a00\u8a9e\u3067\u3088\u304f\u3042\u308b\u8a2d\u8a08\u4e0a\u306e\u554f\u984c\u3067\u3042\u308a\u3001\u4e26\u884c\u51e6\u7406\u306b\u304a\u3051\u308b\u30df\u30b9\u3067\u3059\u3002
\u5177\u4f53\u7684\u306a\u4f8b\u306b\u3064\u3044\u3066\u8aac\u660e\u3057\u307e\u3057\u3087\u3046\u3002\u5916\u90e8\u8a2d\u5b9a\uff08\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u63a5\u7d9a\u306a\u3069\u3092\u4f7f\u7528\u3057\u305f\u3082\u306e\u306a\u3069\uff09\u3092\u76e3\u8996\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u8a2d\u8a08\u3057\u307e\u3059\u3002\u307e\u305a\u3001\u6b21\u306e\u3088\u3046\u306a\u5b9f\u88c5\u3092\u3057\u3066\u307f\u307e\u3059\u3002
func main() {\n newWatcher()\n // \u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u5b9f\u884c\u3059\u308b\n}\n\ntype watcher struct { /* \u3044\u304f\u3064\u304b\u306e\u30ea\u30bd\u30fc\u30b9 */ }\n\nfunc newWatcher() {\n w := watcher{}\n go w.watch() // \u5916\u90e8\u8a2d\u5b9a\u3092\u76e3\u8996\u3059\u308b\u30b4\u30eb\u30fc\u30c1\u30f3\u3092\u4f5c\u6210\u3059\u308b\n}\n
\u3053\u306e\u30b3\u30fc\u30c9\u306e\u554f\u984c\u306f\u3001\u30e1\u30a4\u30f3\u306e\u30b4\u30eb\u30fc\u30c1\u30f3\u304c\u7d42\u4e86\u3059\u308b\u3068\uff08\u304a\u305d\u3089\u304f OS \u30b7\u30b0\u30ca\u30eb\u307e\u305f\u306f\u6709\u9650\u306e\u30ef\u30fc\u30af\u30ed\u30fc\u30c9\u306e\u305f\u3081\uff09\u3001\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u304c\u505c\u6b62\u3057\u3066\u3057\u307e\u3046\u3053\u3068\u3067\u3059\u3002\u3057\u305f\u304c\u3063\u3066\u3001\u30a6\u30a9\u30c3\u30c1\u30e3\u30fc\u306b\u3088\u3063\u3066\u4f5c\u6210\u3055\u308c\u305f\u30ea\u30bd\u30fc\u30b9\u306f\u6b63\u5e38\u306b\u9589\u3058\u3089\u308c\u307e\u305b\u3093\u3002\u3053\u308c\u3092\u9632\u3050\u306b\u306f\u3069\u3046\u3059\u308c\u3070\u3088\u3044\u3067\u3057\u3087\u3046\u304b\u3002
1 \u3064\u306e\u65b9\u6cd5\u3068\u3057\u3066\u306f\u3001main \u304c\u623b\u3063\u305f\u3068\u304d\u306b\u30ad\u30e3\u30f3\u30bb\u30eb\u3055\u308c\u308b Context \u3092 newWatcher \u306b\u6e21\u3059\u3053\u3068\u304c\u6319\u3052\u3089\u308c\u307e\u3059\u3002
func main() {\n ctx, cancel := context.WithCancel(context.Background())\n defer cancel()\n newWatcher(ctx)\n // \u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u5b9f\u884c\u3059\u308b\n}\n\nfunc newWatcher(ctx context.Context) {\n w := watcher{}\n go w.watch(ctx)\n}\n
\u4f5c\u6210\u3057\u305f Context \u3092 watch \u30e1\u30bd\u30c3\u30c9\u306b\u4f1d\u64ad\u3057\u307e\u3059\u3002Context \u304c\u30ad\u30e3\u30f3\u30bb\u30eb\u3055\u308c\u308b\u3068\u3001\u30a6\u30a9\u30c3\u30c1\u30e3\u30fc\u69cb\u9020\u4f53\u306f\u305d\u306e\u30ea\u30bd\u30fc\u30b9\u3092\u9589\u3058\u307e\u3059\u3002\u3057\u304b\u3057\u3001watch \u304c\u305d\u308c\u3092\u884c\u3046\u6642\u9593\u304c\u78ba\u5b9f\u306b\u3042\u308b\u3068\u306f\u3044\u3048\u307e\u305b\u3093\u3002\u3053\u308c\u306f\u8a2d\u8a08\u4e0a\u306e\u6b20\u9665\u3067\u3059\u3002
\u554f\u984c\u306f\u3001\u30b4\u30eb\u30fc\u30c1\u30f3\u3092\u505c\u6b62\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u3053\u3068\u3092\u4f1d\u3048\u308b\u305f\u3081\u306b\u30b7\u30b0\u30ca\u30eb\u3092\u4f7f\u7528\u3057\u305f\u3053\u3068\u3067\u3059\u3002\u30ea\u30bd\u30fc\u30b9\u304c\u9589\u3058\u3089\u308c\u308b\u307e\u3067\u3001\u89aa\u306e\u30b4\u30eb\u30fc\u30c1\u30f3\u3092\u30d6\u30ed\u30c3\u30af\u3057\u307e\u305b\u3093\u3067\u3057\u305f\u3002\u305d\u3046\u306a\u3089\u306a\u3044\u3088\u3046\u306b\u3057\u307e\u3057\u3087\u3046\u3002
func main() {\n w := newWatcher()\n defer w.close()\n // \u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u5b9f\u884c\u3059\u308b\n}\n\nfunc newWatcher() watcher {\n w := watcher{}\n go w.watch()\n return w\n}\n\nfunc (w watcher) close() {\n // \u30ea\u30bd\u30fc\u30b9\u3092\u9589\u3058\u308b\n}\n
\u30ea\u30bd\u30fc\u30b9\u3092\u9589\u3058\u308b\u6642\u9593\u306b\u306a\u3063\u305f\u3053\u3068\u3092 watcher
\u306b\u901a\u77e5\u3059\u308b\u4ee3\u308f\u308a\u306b\u3001 defer
\u3092\u4f7f\u7528\u3057\u3066\u3053\u306e\u3000close
\u30e1\u30bd\u30c3\u30c9\u3092\u547c\u3073\u51fa\u3057\u3001\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u304c\u7d42\u4e86\u3059\u308b\u524d\u306b\u30ea\u30bd\u30fc\u30b9\u304c\u78ba\u5b9f\u306b\u9589\u3058\u3089\u308c\u308b\u3088\u3046\u306b\u3057\u307e\u3059\u3002
\u307e\u3068\u3081\u308b\u3068\u3001\u30b4\u30eb\u30fc\u30c1\u30f3\u306f\u4ed6\u306e\u30ea\u30bd\u30fc\u30b9\u3068\u540c\u69d8\u3001\u30e1\u30e2\u30ea\u3084\u4ed6\u306e\u30ea\u30bd\u30fc\u30b9\u3092\u89e3\u653e\u3059\u308b\u305f\u3081\u306b\u6700\u7d42\u7684\u306b\u9589\u3058\u308b\u5fc5\u8981\u304c\u3042\u308b\u3053\u3068\u306b\u6ce8\u610f\u3057\u3066\u304f\u3060\u3055\u3044\u3002\u30b4\u30eb\u30fc\u30c1\u30f3\u3092\u3044\u3064\u505c\u6b62\u3059\u308b\u304b\u3092\u77e5\u3089\u305a\u306b\u958b\u59cb\u3059\u308b\u306e\u306f\u8a2d\u8a08\u4e0a\u306e\u554f\u984c\u3067\u3059\u3002\u30b4\u30eb\u30fc\u30c1\u30f3\u304c\u958b\u59cb\u3055\u308c\u308b\u3068\u304d\u306f\u5e38\u306b\u3001\u3044\u3064\u505c\u6b62\u3059\u308b\u304b\u306b\u3064\u3044\u3066\u660e\u78ba\u306a\u8a08\u753b\u3092\u7acb\u3066\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u6700\u5f8c\u306b\u306a\u308a\u307e\u3057\u305f\u304c\u3001\u30b4\u30eb\u30fc\u30c1\u30f3\u304c\u30ea\u30bd\u30fc\u30b9\u3092\u4f5c\u6210\u3057\u3001\u305d\u306e\u6709\u52b9\u671f\u9593\u304c\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u5b58\u7d9a\u671f\u9593\u306b\u30d0\u30a4\u30f3\u30c9\u3055\u308c\u3066\u3044\u308b\u5834\u5408\u306f\u3001\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u7d42\u4e86\u3059\u308b\u524d\u306b\u305d\u306e\u30b4\u30eb\u30fc\u30c1\u30f3\u304c\u5b8c\u4e86\u3059\u308b\u306e\u3092\u5f85\u3063\u305f\u65b9\u304c\u304a\u305d\u3089\u304f\u78ba\u5b9f\u3067\u3059\u3002\u305d\u3046\u3059\u308b\u3053\u3068\u3067\u3001\u30ea\u30bd\u30fc\u30b9\u3092\u9593\u9055\u3044\u306a\u304f\u89e3\u653e\u3067\u304d\u307e\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#63","title":"\u30b4\u30eb\u30fc\u30c1\u30f3\u3068\u30eb\u30fc\u30d7\u5909\u6570\u306b\u6ce8\u610f\u3057\u306a\u3044 (#63)","text":"\u6ce8\u610f\u3053\u306e\u30df\u30b9\u306f Go\u30001.22 \u304b\u3089\u306f\u6c17\u306b\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u305b\u3093\uff08\u8a73\u7d30\uff09\u3002
"},{"location":"ja/#select-64","title":"select
\u3068\u30c1\u30e3\u30cd\u30eb\u3092\u4f7f\u7528\u3057\u3066\u6c7a\u5b9a\u7684\u52d5\u4f5c\u3092\u671f\u5f85\u3059\u308b (#64)","text":"\u8981\u7d04 \u8907\u6570\u306e\u30aa\u30d7\u30b7\u30e7\u30f3\u304c\u53ef\u80fd\u306a\u5834\u5408\u3001\u8907\u6570\u306e\u30c1\u30e3\u30cd\u30eb\u3067 select
\u3059\u308b\u3068\u30b1\u30fc\u30b9\u304c\u30e9\u30f3\u30c0\u30e0\u306b\u9078\u629e\u3055\u308c\u308b\u3053\u3068\u3092\u7406\u89e3\u3059\u308b\u3068\u3001\u4e26\u884c\u51e6\u7406\u306b\u304a\u3051\u308b\u8efd\u5fae\u306a\u30d0\u30b0\u306b\u3064\u306a\u304c\u308b\u53ef\u80fd\u6027\u306e\u3042\u308b\u8aa4\u3063\u305f\u4eee\u5b9a\u3092\u7acb\u3066\u308b\u3053\u3068\u304c\u306a\u304f\u306a\u308a\u307e\u3059\u3002
Go \u958b\u767a\u8005\u304c\u30c1\u30e3\u30cd\u30eb\u3092\u64cd\u4f5c\u3059\u308b\u3068\u304d\u306b\u3042\u308a\u304c\u3061\u306a\u9593\u9055\u3044\u306e 1 \u3064\u306f\u3001select \u304c\u8907\u6570\u306e\u30c1\u30e3\u30cd\u30eb\u3067\u3069\u306e\u3088\u3046\u306b\u52d5\u4f5c\u3059\u308b\u304b\u306b\u3064\u3044\u3066\u8aa4\u3063\u305f\u7406\u89e3\u3092\u3059\u308b\u3053\u3068\u3067\u3059\u3002
\u305f\u3068\u3048\u3070\u3001\u6b21\u306e\u5834\u5408\u3092\u8003\u3048\u3066\u307f\u307e\u3057\u3087\u3046\uff08 disconnectCh
\u306f\u30d0\u30c3\u30d5\u30a1\u306a\u3057\u30c1\u30e3\u30cd\u30eb\u3067\u3059\uff09\u3002
go func() {\n for i := 0; i < 10; i++ {\n messageCh <- i\n }\n disconnectCh <- struct{}{}\n}()\n\nfor {\n select {\n case v := <-messageCh:\n fmt.Println(v)\n case <-disconnectCh:\n fmt.Println(\"disconnection, return\")\n return\n }\n}\n
\u3053\u306e\u4f8b\u3092\u8907\u6570\u56de\u5b9f\u884c\u3057\u305f\u5834\u5408\u3001\u7d50\u679c\u306f\u30e9\u30f3\u30c0\u30e0\u306b\u306a\u308a\u307e\u3059\u3002
0\n1\n2\ndisconnection, return\n\n0\ndisconnection, return\n
\u3069\u3046\u3044\u3046\u308f\u3051\u304b 10 \u901a\u306e\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u6d88\u8cbb\u3059\u308b\u306e\u3067\u306f\u306a\u304f\u3001\u305d\u306e\u3046\u3061\u306e\u6570\u901a\u3060\u3051\u3092\u53d7\u4fe1\u3057\u307e\u3057\u305f\u3002\u3053\u308c\u306f\u3001\u8907\u6570\u306e\u30c1\u30e3\u30cd\u30eb\u3068\u4f75\u7528\u3057\u305f\u5834\u5408\u306e select \u6587\u306e\u4ed5\u69d8\u306b\u3088\u308b\u3082\u306e\u3067\u3059\uff08https:// go.dev/ref/spec\uff09\u3002
Quote
1 \u3064\u4ee5\u4e0a\u306e\u901a\u4fe1\u3092\u7d9a\u884c\u3067\u304d\u308b\u5834\u5408\u3001\u5747\u4e00\u306e\u64ec\u4f3c\u30e9\u30f3\u30c0\u30e0\u9078\u629e\u306b\u3088\u3063\u3066\u3001\u7d9a\u884c\u3067\u304d\u308b 1 \u3064\u306e\u901a\u4fe1\u304c\u9078\u629e\u3055\u308c\u307e\u3059\u3002
\u6700\u521d\u306b\u4e00\u81f4\u3057\u305f\u30b1\u30fc\u30b9\u304c\u512a\u5148\u3055\u308c\u308b switch \u6587\u3068\u306f\u7570\u306a\u308a\u3001select \u6587\u306f\u8907\u6570\u306e\u30aa\u30d7\u30b7\u30e7\u30f3\u304c\u53ef\u80fd\u306a\u5834\u5408\u306b\u30e9\u30f3\u30c0\u30e0\u306b\u9078\u629e\u3057\u307e\u3059\u3002
\u3053\u306e\u52d5\u4f5c\u306f\u6700\u521d\u306f\u5947\u5999\u306b\u601d\u3048\u308b\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002\u3057\u304b\u3057\u3001\u3053\u308c\u306f\u30b9\u30bf\u30d9\u30fc\u30b7\u30e7\u30f3\u3092\u9632\u3050\u3068\u3044\u3046\u7406\u7531\u304c\u3042\u3063\u3066\u306e\u3053\u3068\u3067\u3059\u3002\u6700\u521d\u306b\u9078\u629e\u3055\u308c\u305f\u901a\u4fe1\u304c\u30bd\u30fc\u30b9\u306e\u9806\u5e8f\u306b\u57fa\u3065\u3044\u3066\u3044\u308b\u3068\u3057\u307e\u3059\u3002\u305d\u306e\u5834\u5408\u3001\u9001\u4fe1\u901f\u5ea6\u304c\u901f\u3044\u305f\u3081\u306b\u3001\u305f\u3068\u3048\u3070 1 \u3064\u306e\u30c1\u30e3\u30cd\u30eb\u304b\u3089\u3057\u304b\u53d7\u4fe1\u3067\u304d\u306a\u3044\u3068\u3044\u3046\u72b6\u6cc1\u306b\u9665\u308b\u53ef\u80fd\u6027\u304c\u3042\u308a\u307e\u3059\u3002\u3053\u308c\u3092\u9632\u3050\u305f\u3081\u306b\u3001Go\u8a00\u8a9e\u306e\u8a2d\u8a08\u8005\u306f\u30e9\u30f3\u30c0\u30e0\u9078\u629e\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u306b\u3057\u307e\u3057\u305f\u3002
\u8907\u6570\u306e\u30c1\u30e3\u30cd\u30eb\u3067 select
\u3092\u4f7f\u7528\u3059\u308b\u5834\u5408\u3001\u8907\u6570\u306e\u30aa\u30d7\u30b7\u30e7\u30f3\u304c\u3042\u308b\u306a\u3089\u3001\u30bd\u30fc\u30b9\u9806\u5e8f\u306e\u6700\u521d\u306e\u30b1\u30fc\u30b9\u304c\u81ea\u52d5\u7684\u306b\u512a\u5148\u3055\u308c\u308b\u308f\u3051\u3067\u306f\u306a\u3044\u3053\u3068\u306b\u6ce8\u610f\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u4ee3\u308f\u308a\u306b\u3001Go\u8a00\u8a9e\u306f\u30e9\u30f3\u30c0\u30e0\u306b\u9078\u629e\u3059\u308b\u305f\u3081\u3001\u3069\u306e\u30aa\u30d7\u30b7\u30e7\u30f3\u304c\u9078\u629e\u3055\u308c\u308b\u304b\u306f\u4fdd\u8a3c\u3055\u308c\u307e\u305b\u3093\u3002\u3053\u306e\u52d5\u4f5c\u3092\u514b\u670d\u3059\u308b\u306b\u306f\u3001\u5358\u4e00\u306e\u751f\u7523\u8005\u30b4\u30eb\u30fc\u30c1\u30f3\u306e\u5834\u5408\u3001\u30d0\u30c3\u30d5\u30a1\u306a\u3057\u306e\u30c1\u30e3\u30cd\u30eb\u307e\u305f\u306f\u5358\u4e00\u306e\u30c1\u30e3\u30cd\u30eb\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#65","title":"\u901a\u77e5\u30c1\u30e3\u30cd\u30eb\u3092\u4f7f\u7528\u3057\u3066\u3044\u306a\u3044 (#65)","text":"\u8981\u7d04chan struct{}
\u578b\u3092\u4f7f\u7528\u3057\u3066\u901a\u77e5\u3092\u9001\u4fe1\u3057\u307e\u3057\u3087\u3046\u3002
\u30c1\u30e3\u30cd\u30eb\u306f\u3001\u30b7\u30b0\u30ca\u30eb\u3092\u4ecb\u3057\u3066\u30b4\u30eb\u30fc\u30c1\u30f3\u9593\u3067\u901a\u4fe1\u3059\u308b\u305f\u3081\u306e\u30e1\u30ab\u30cb\u30ba\u30e0\u3067\u3059\u3002\u30b7\u30b0\u30ca\u30eb\u306b\u306f\u30c7\u30fc\u30bf\u304c\u542b\u307e\u308c\u3066\u3044\u308b\u304b\u3069\u3046\u304b\u306f\u95a2\u4fc2\u3042\u308a\u307e\u305b\u3093\u3002
\u5177\u4f53\u7684\u306a\u4f8b\u3092\u898b\u3066\u307f\u307e\u3057\u3087\u3046\u3002\u901a\u4fe1\u306e\u5207\u65ad\u304c\u767a\u751f\u3059\u308b\u305f\u3073\u306b\u305d\u308c\u3092\u901a\u77e5\u3059\u308b\u30c1\u30e3\u30cd\u30eb\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002 1 \u3064\u306e\u65b9\u6cd5\u3068\u3057\u3066\u3001\u3053\u308c\u3092 chan bool
\u3068\u3057\u3066\u6271\u3046\u3053\u3068\u304c\u6319\u3052\u3089\u308c\u307e\u3059\u3002
disconnectCh := make(chan bool)\n
\u3053\u3053\u3067\u3001\u305d\u306e\u3088\u3046\u306a\u30c1\u30e3\u30cd\u30eb\u3092\u63d0\u4f9b\u3059\u308b API \u3068\u5bfe\u8a71\u3059\u308b\u3068\u3057\u307e\u3059\u3002\u3053\u308c\u306f\u771f\u507d\u5024\u306e\u30c1\u30e3\u30cd\u30eb\u3067\u3042\u308b\u305f\u3081\u3001true
\u307e\u305f\u306f false
\u306e\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u53d7\u4fe1\u3067\u304d\u307e\u3059\u3002true
\u304c\u4f55\u3092\u4f1d\u3048\u3066\u3044\u308b\u304b\u306f\u304a\u305d\u3089\u304f\u660e\u3089\u304b\u3067\u3057\u3087\u3046\u3002\u3057\u304b\u3057\u3001 false
\u3068\u306f\u4f55\u3092\u610f\u5473\u3059\u308b\u306e\u3067\u3057\u3087\u3046\u304b\u3002\u901a\u4fe1\u304c\u5207\u65ad\u3055\u308c\u3066\u3044\u306a\u3044\u3068\u3044\u3046\u3053\u3068\u3067\u3057\u3087\u3046\u304b\u3002\u305d\u306e\u5834\u5408\u3001\u3069\u308c\u304f\u3089\u3044\u306e\u983b\u5ea6\u3067\u305d\u306e\u3088\u3046\u306a\u30b7\u30b0\u30ca\u30eb\u3092\u53d7\u4fe1\u3059\u308b\u306e\u3067\u3057\u3087\u3046\u304b\u3002\u3042\u308b\u3044\u306f\u518d\u63a5\u7d9a\u3057\u305f\u3068\u3044\u3046\u3053\u3068\u3067\u3057\u3087\u3046\u304b\u3002\u305d\u3082\u305d\u3082 false
\u3092\u53d7\u3051\u53d6\u308b\u3053\u3068\u3092\u671f\u5f85\u3059\u3079\u304d\u306a\u306e\u3067\u3057\u3087\u3046\u304b\u3002\u304a\u305d\u3089\u304f true
\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u53d7\u3051\u53d6\u308b\u3053\u3068\u3060\u3051\u3092\u671f\u5f85\u3059\u3079\u304d\u3067\u3057\u3087\u3046\u3002
\u305d\u306e\u5834\u5408\u3001\u60c5\u5831\u3092\u4f1d\u3048\u308b\u305f\u3081\u306b\u7279\u5b9a\u306e\u5024\u306f\u5fc5\u8981\u306a\u3044\u3053\u3068\u3092\u610f\u5473\u3057\u3001\u30c7\u30fc\u30bf\u306e \u306a\u3044 \u30c1\u30e3\u30cd\u30eb\u304c\u5fc5\u8981\u306b\u306a\u308a\u307e\u3059\u3002\u3053\u308c\u3092\u51e6\u7406\u3059\u308b\u6163\u7528\u7684\u306a\u65b9\u6cd5\u306f\u3001\u7a7a\u306e\u69cb\u9020\u4f53\u306e\u30c1\u30e3\u30cd\u30eb\u2015\u2015 chan struct{}
\u2015\u2015\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u3067\u3059\u3002
nil \u30c1\u30e3\u30cd\u30eb\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u306b\u3088\u3063\u3066\u3001\u305f\u3068\u3048\u3070 select
\u6587\u304b\u3089\u30b1\u30fc\u30b9\u3092 \u524a\u9664 \u3067\u304d\u308b\u305f\u3081\u3001\u4e26\u884c\u51e6\u7406\u3092\u884c\u3046\u969b\u306e\u9053\u5177\u306e\u4e00\u3064\u3068\u3057\u3066\u4f7f\u3048\u308b\u3088\u3046\u306b\u306a\u308b\u3079\u304d\u3067\u3059\u3002
\u6b21\u306e\u30b3\u30fc\u30c9\u306b\u3088\u3063\u3066\u4f55\u304c\u884c\u308f\u308c\u308b\u3067\u3057\u3087\u3046\u304b\u3002
var ch chan int\n<-ch\n
ch
\u306f chan int
\u578b\u3067\u3059\u3002\u30c1\u30e3\u30cd\u30eb\u306e\u30bc\u30ed\u5024\u306f nil \u3067\u3042\u308b\u306e\u3067\u3001 ch
\u306f nil
\u3067\u3059\u3002\u30b4\u30eb\u30fc\u30c1\u30f3\u306f panic \u3092\u8d77\u3053\u3057\u307e\u305b\u3093\u3002\u305f\u3060\u3057\u3001\u6c38\u4e45\u306b\u30d6\u30ed\u30c3\u30af\u3057\u307e\u3059\u3002
nil \u30c1\u30e3\u30cd\u30eb\u306b\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u9001\u4fe1\u3059\u308b\u5834\u5408\u3082\u539f\u7406\u306f\u540c\u3058\u3067\u3059\u3002\u4ee5\u4e0b\u306e\u30b4\u30eb\u30fc\u30c1\u30f3\u306f\u6c38\u4e45\u306b\u30d6\u30ed\u30c3\u30af\u3057\u307e\u3059\u3002
var ch chan int\nch <- 0\n
\u3067\u306f\u3001Go\u8a00\u8a9e\u304c nil \u30c1\u30e3\u30cd\u30eb\u3068\u306e\u9593\u3067\u30e1\u30c3\u30bb\u30fc\u30b8\u306e\u9001\u53d7\u4fe1\u3092\u8a31\u53ef\u3059\u308b\u76ee\u7684\u306f\u4f55\u3067\u3057\u3087\u3046\u304b\u3002\u305f\u3068\u3048\u3070\u30012 \u3064\u306e\u30c1\u30e3\u30cd\u30eb\u3092\u30de\u30fc\u30b8\u3059\u308b\u6163\u7528\u7684\u306a\u65b9\u6cd5\u3092\u5b9f\u88c5\u3059\u308b\u306e\u306b\u3001 nil \u30c1\u30e3\u30cd\u30eb\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002
func merge(ch1, ch2 <-chan int) <-chan int {\n ch := make(chan int, 1)\n\n go func() {\n for ch1 != nil || ch2 != nil { // \u6700\u4f4e\u3067\u3082\u4e00\u3064\u306e\u30c1\u30e3\u30cd\u30eb\u304c nil \u3067\u306a\u3051\u308c\u3070\u7d9a\u884c\u3059\u308b\n select {\n case v, open := <-ch1:\n if !open {\n ch1 = nil // \u9589\u3058\u305f\u3089 ch1 \u3092 nil \u30c1\u30e3\u30cd\u30eb\u306b\u5272\u308a\u5f53\u3066\u308b\n break\n }\n ch <- v\n case v, open := <-ch2:\n if !open {\n ch2 = nil // \u9589\u3058\u305f\u3089 ch2 \u3092 nil \u30c1\u30e3\u30cd\u30eb\u306b\u5272\u308a\u5f53\u3066\u308b\n break\n }\n ch <- v\n }\n }\n close(ch)\n }()\n\n return ch\n}\n
\u3053\u306e\u6d17\u7df4\u3055\u308c\u305f\u89e3\u6c7a\u7b56\u306f\u3001nil \u30c1\u30e3\u30cd\u30eb\u3092\u5229\u7528\u3057\u3066\u3001\u4f55\u3089\u304b\u306e\u65b9\u6cd5\u3067 select
\u6587\u304b\u3089 1 \u3064\u306e\u30b1\u30fc\u30b9\u3092 \u524a\u9664 \u3057\u307e\u3059\u3002
nil \u30c1\u30e3\u30cd\u30eb\u306f\u72b6\u6cc1\u306b\u3088\u3063\u3066\u306f\u4fbf\u5229\u3067\u3042\u308a\u3001Go \u958b\u767a\u8005\u306f\u4e26\u884c\u51e6\u7406\u3092\u6271\u3046\u969b\u306b\u4f7f\u3044\u3053\u306a\u305b\u308b\u3088\u3046\u306b\u306a\u3063\u3066\u304a\u304f\u3079\u304d\u3067\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#67","title":"\u30c1\u30e3\u30cd\u30eb\u306e\u5bb9\u91cf\u306b\u3064\u3044\u3066\u56f0\u60d1\u3057\u3066\u3044\u308b (#67)","text":"\u8981\u7d04\u554f\u984c\u304c\u767a\u751f\u3057\u305f\u5834\u5408\u306f\u3001\u4f7f\u7528\u3059\u308b\u30c1\u30e3\u30cd\u30eb\u306e\u578b\u3092\u614e\u91cd\u306b\u6c7a\u5b9a\u3057\u3066\u304f\u3060\u3055\u3044\u3002\u540c\u671f\u3092\u5f37\u529b\u306b\u4fdd\u8a3c\u3057\u3066\u304f\u308c\u308b\u306e\u306f\u30d0\u30c3\u30d5\u30a1\u306a\u3057\u30c1\u30e3\u30cd\u30eb\u306e\u307f\u3067\u3059\u3002
\u30d0\u30c3\u30d5\u30a1\u3042\u308a\u30c1\u30e3\u30cd\u30eb\u4ee5\u5916\u306e\u30c1\u30e3\u30cd\u30eb\u306e\u5bb9\u91cf\u3092\u6307\u5b9a\u3059\u308b\u306b\u306f\u6b63\u5f53\u306a\u7406\u7531\u304c\u3042\u308b\u3079\u304d\u3067\u3059\u3002
"},{"location":"ja/#etcd-68","title":"\u6587\u5b57\u5217\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u3067\u8d77\u3053\u308a\u5f97\u308b\u526f\u4f5c\u7528\u3092\u5fd8\u308c\u3066\u3057\u307e\u3046\uff08 etcd \u30c7\u30fc\u30bf\u7af6\u5408\u306e\u4f8b\u3068\u30c7\u30c3\u30c9\u30ed\u30c3\u30af\uff09 (#68)","text":"\u8981\u7d04\u6587\u5b57\u5217\u306e\u66f8\u5f0f\u8a2d\u5b9a\u304c\u65e2\u5b58\u306e\u95a2\u6570\u304c\u547c\u3073\u51fa\u3059\u53ef\u80fd\u6027\u304c\u3042\u308b\u3053\u3068\u3092\u8a8d\u8b58\u3059\u308b\u3053\u3068\u306f\u3001\u30c7\u30c3\u30c9\u30ed\u30c3\u30af\u3084\u305d\u306e\u4ed6\u306e\u30c7\u30fc\u30bf\u7af6\u5408\u306e\u53ef\u80fd\u6027\u306b\u6ce8\u610f\u3059\u308b\u3053\u3068\u3092\u610f\u5473\u3057\u307e\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#append-69","title":"append
\u3067\u30c7\u30fc\u30bf\u7af6\u5408\u3092\u8d77\u3053\u3057\u3066\u3057\u307e\u3046 (#69)","text":"\u8981\u7d04 append
\u306e\u547c\u3073\u51fa\u3057\u306f\u5fc5\u305a\u3057\u3082\u30c7\u30fc\u30bf\u7af6\u5408\u304c\u306a\u3044\u308f\u3051\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u3002\u3086\u3048\u306b\u3001\u5171\u6709\u30b9\u30e9\u30a4\u30b9\u4e0a\u3067\u540c\u6642\u306b\u4f7f\u7528\u3057\u3066\u306f\u3044\u3051\u307e\u305b\u3093\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#70","title":"\u30b9\u30e9\u30a4\u30b9\u3068\u30de\u30c3\u30d7\u3067\u30df\u30e5\u30fc\u30c6\u30c3\u30af\u30b9\u3092\u6b63\u3057\u304f\u4f7f\u7528\u3057\u3066\u3044\u306a\u3044 (#70)","text":"\u8981\u7d04\u30b9\u30e9\u30a4\u30b9\u3068\u30de\u30c3\u30d7\u306f\u30dd\u30a4\u30f3\u30bf\u3067\u3042\u308b\u3053\u3068\u3092\u899a\u3048\u3066\u304a\u304f\u3068\u3001\u5178\u578b\u7684\u306a\u30c7\u30fc\u30bf\u7af6\u5408\u3092\u9632\u3050\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#syncwaitgroup-71","title":"sync.WaitGroup
\u3092\u6b63\u3057\u304f\u4f7f\u7528\u3057\u3066\u3044\u306a\u3044 (#71)","text":"\u8981\u7d04 sync.WaitGroup
\u3092\u6b63\u3057\u304f\u4f7f\u7528\u3059\u308b\u306b\u306f\u3001\u30b4\u30eb\u30fc\u30c1\u30f3\u3092\u8d77\u52d5\u3059\u308b\u524d\u306b Add
\u30e1\u30bd\u30c3\u30c9\u3092\u547c\u3073\u51fa\u3057\u307e\u3057\u3087\u3046\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#synccond-72","title":"sync.Cond
\u306b\u3064\u3044\u3066\u5fd8\u308c\u3066\u3057\u307e\u3046 (#72)","text":"\u8981\u7d04 sync.Cond
\u3092\u4f7f\u7528\u3059\u308b\u3068\u3001\u8907\u6570\u306e\u30b4\u30eb\u30fc\u30c1\u30f3\u306b\u7e70\u308a\u8fd4\u3057\u901a\u77e5\u3092\u9001\u4fe1\u3067\u304d\u307e\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#errgroup-73","title":"errgroup
\u3092\u4f7f\u7528\u3057\u3066\u3044\u306a\u3044 (#73)","text":"\u8981\u7d04 errgroup
\u30d1\u30c3\u30b1\u30fc\u30b8\u3092\u4f7f\u7528\u3057\u3066\u3001\u30b4\u30eb\u30fc\u30c1\u30f3\u306e\u30b0\u30eb\u30fc\u30d7\u3092\u540c\u671f\u3057\u3001\u30a8\u30e9\u30fc\u3068 Context \u3092\u51e6\u7406\u3067\u304d\u307e\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#sync-74","title":"sync
\u578b\u306e\u30b3\u30d4\u30fc (#74)","text":"\u8981\u7d04 sync
\u578b\u306f\u30b3\u30d4\u30fc\u3055\u308c\u308b\u3079\u304d\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#_15","title":"\u6a19\u6e96\u30e9\u30a4\u30d6\u30e9\u30ea","text":""},{"location":"ja/#75","title":"\u9593\u9055\u3063\u305f\u6642\u9593\u3092\u6307\u5b9a\u3059\u308b (#75)","text":"\u8981\u7d04time.Duration
\u3092\u53d7\u3051\u5165\u308c\u308b\u95a2\u6570\u306b\u306f\u6ce8\u610f\u3092\u6255\u3063\u3066\u304f\u3060\u3055\u3044\u3002\u6574\u6570\u3092\u6e21\u3059\u3053\u3068\u306f\u8a31\u53ef\u3055\u308c\u3066\u3044\u307e\u3059\u304c\u3001\u6df7\u4e71\u3092\u62db\u304b\u306a\u3044\u3088\u3046\u306b time API \u3092\u4f7f\u7528\u3059\u308b\u3088\u3046\u52aa\u3081\u3066\u304f\u3060\u3055\u3044\u3002
\u6a19\u6e96\u30e9\u30a4\u30d6\u30e9\u30ea\u306e\u591a\u304f\u306e\u95a2\u6570\u306f\u3001int64
\u578b\u306e\u30a8\u30a4\u30ea\u30a2\u30b9\u3067\u3042\u308b time.Duration
\u3092\u53d7\u3051\u5165\u308c\u307e\u3059\u3002\u305f\u3060\u3057\u30011 \u5358\u4f4d\u306e time.Duration
\u306f\u3001\u4ed6\u306e\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u8a00\u8a9e\u3067\u4e00\u822c\u7684\u306b\u898b\u3089\u308c\u308b 1 \u30df\u30ea\u79d2\u3067\u306f\u306a\u304f\u30011 \u30ca\u30ce\u79d2\u3092\u8868\u3057\u307e\u3059\u3002\u305d\u306e\u7d50\u679c\u3001time.Duration
API \u3092\u4f7f\u7528\u3059\u308b\u4ee3\u308f\u308a\u306b\u6570\u5024\u578b\u3092\u6e21\u3059\u3068\u3001\u4e88\u60f3\u5916\u306e\u52d5\u4f5c\u304c\u767a\u751f\u3059\u308b\u53ef\u80fd\u6027\u304c\u3042\u308a\u307e\u3059\u3002
\u4ed6\u8a00\u8a9e\u3092\u4f7f\u7528\u3057\u305f\u3053\u3068\u306e\u3042\u308b\u958b\u767a\u8005\u306e\u65b9\u306f\u3001\u6b21\u306e\u30b3\u30fc\u30c9\u306b\u3088\u3063\u3066 1 \u79d2\u5468\u671f\u306e\u65b0\u3057\u3044 time.Ticker
\u304c\u751f\u6210\u3055\u308c\u308b\u3068\u8003\u3048\u308b\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002
ticker := time.NewTicker(1000)\nfor {\n select {\n case <-ticker.C:\n // \u51e6\u7406\u3092\u3059\u308b\n }\n}\n
\u3057\u304b\u3057\u306a\u304c\u3089\u30011,000 time.Duration
= 1,000 \u30ca\u30ce\u79d2\u3067\u3042\u308b\u305f\u3081\u3001\u60f3\u5b9a\u3055\u308c\u3066\u3044\u308b 1\u79d2 \u3067\u306f\u306a\u304f\u30011,000 \u30ca\u30ce\u79d2 = 1 \u30de\u30a4\u30af\u30ed\u79d2\u306e\u5468\u671f\u306b\u306a\u308a\u307e\u3059\u3002
\u6df7\u4e71\u3084\u4e88\u60f3\u5916\u306e\u52d5\u4f5c\u3092\u62db\u304b\u306a\u3044\u3088\u3046\u3001\u3044\u3064\u3082 time.Duration
API \u3092\u4f7f\u7528\u3059\u308b\u3079\u304d\u3067\u3059\u3002
ticker = time.NewTicker(time.Microsecond)\n// \u3082\u3057\u304f\u306f\nticker = time.NewTicker(1000 * time.Nanosecond)\n
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#timeafter-76","title":"time.After
\u3068\u30e1\u30e2\u30ea\u30ea\u30fc\u30af (#76)","text":"\u8981\u7d04 \u7e70\u308a\u8fd4\u3055\u308c\u308b\u95a2\u6570\uff08\u30eb\u30fc\u30d7\u3084 HTTP \u30cf\u30f3\u30c9\u30e9\u306a\u3069\uff09\u3067 time.After
\u306e\u547c\u3073\u51fa\u3057\u3092\u56de\u907f\u3059\u308b\u3068\u3001\u30d4\u30fc\u30af\u6642\u306e\u30e1\u30e2\u30ea\u6d88\u8cbb\u3092\u56de\u907f\u3067\u304d\u307e\u3059\u3002time.After
\u306b\u3088\u3063\u3066\u751f\u6210\u3055\u308c\u305f\u30ea\u30bd\u30fc\u30b9\u306f\u3001 timer \u304c\u7d42\u4e86\u3057\u305f\u3068\u304d\u306b\u306e\u307f\u89e3\u653e\u3055\u308c\u307e\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#json-77","title":"JSON \u51e6\u7406\u3067\u3042\u308a\u304c\u3061\u306a\u9593\u9055\u3044 (#77)","text":"Go \u69cb\u9020\u4f53\u3067\u57cb\u3081\u8fbc\u307f\u30d5\u30a3\u30fc\u30eb\u30c9\u3092\u4f7f\u7528\u3059\u308b\u5834\u5408\u306f\u6ce8\u610f\u3057\u3066\u304f\u3060\u3055\u3044\u3002 \u306a\u305c\u306a\u3089 json.Marshaler
\u30a4\u30f3\u30bf\u30d5\u30a7\u30fc\u30b9\u3092\u5b9f\u88c5\u3059\u308b time.Time \u57cb\u3081\u8fbc\u307f\u30d5\u30a3\u30fc\u30eb\u30c9\u306e\u3088\u3046\u306a\u3084\u3063\u304b\u3044\u306a\u30d0\u30b0\u304c\u767a\u751f\u3057\u3066\u3001\u30c7\u30d5\u30a9\u30eb\u30c8\u306e\u30de\u30fc\u30b7\u30e3\u30ea\u30f3\u30b0\u52d5\u4f5c\u304c\u30aa\u30fc\u30d0\u30fc\u30e9\u30a4\u30c9\u3055\u308c\u308b\u53ef\u80fd\u6027\u304c\u3042\u308b\u304b\u3089\u3067\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
2 \u3064\u306e time.Time
\u69cb\u9020\u4f53\u3092\u6bd4\u8f03\u3059\u308b\u5834\u5408\u3001time.Time
\u306b\u306f wall clock \u3068 monotonic clock \u306e\u4e21\u65b9\u304c\u542b\u307e\u308c\u3066\u304a\u308a\u3001== \u6f14\u7b97\u5b50\u3092\u4f7f\u7528\u3057\u305f\u6bd4\u8f03\u306f\u4e21\u65b9\u306e clock \u306b\u5bfe\u3057\u3066\u884c\u308f\u308c\u308b\u3053\u3068\u3092\u601d\u3044\u51fa\u3057\u3066\u304f\u3060\u3055\u3044\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
any
\u306e\u30de\u30c3\u30d7JSON \u30c7\u30fc\u30bf\u306e\u30a2\u30f3\u30de\u30fc\u30b7\u30e3\u30ea\u30f3\u30b0\u4e2d\u306b\u30de\u30c3\u30d7\u3092\u63d0\u4f9b\u3059\u308b\u3068\u304d\u306b\u9593\u9055\u3044\u3092\u907f\u3051\u308b\u305f\u3081\u306b\u3001\u6570\u5024\u306f\u30c7\u30d5\u30a9\u30eb\u30c8\u3067 float64
\u306b\u5909\u63db\u3055\u308c\u308b\u3053\u3068\u306b\u6ce8\u610f\u3057\u3066\u304f\u3060\u3055\u3044\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#sql-78","title":"SQL \u3067\u3042\u308a\u304c\u3061\u306a\u9593\u9055\u3044 (#78)","text":"sql.Open
\u304c\u5fc5\u305a\u3057\u3082\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3078\u306e\u63a5\u7d9a\u3092\u78ba\u7acb\u3059\u308b\u308f\u3051\u3067\u306f\u306a\u3044\u3053\u3068\u3092\u5fd8\u308c\u3066\u3044\u308b\u8a2d\u5b9a\u3092\u8a66\u3057\u3001\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306b\u30a2\u30af\u30bb\u30b9\u3067\u304d\u308b\u3053\u3068\u3092\u78ba\u8a8d\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u5834\u5408\u306f\u3001 Ping
\u307e\u305f\u306f PingContext
\u30e1\u30bd\u30c3\u30c9\u3092\u547c\u3073\u51fa\u3057\u307e\u3057\u3087\u3046\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
\u5b9f\u904b\u7528\u6c34\u6e96\u306e\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3067\u306f\u3001\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u63a5\u7d9a\u30d1\u30e9\u30e1\u30fc\u30bf\u3092\u8a2d\u5b9a\u3057\u307e\u3057\u3087\u3046\u3002
SQL \u306e\u30d7\u30ea\u30da\u30a2\u30c9\u30b9\u30c6\u30fc\u30c8\u30e1\u30f3\u30c8\u3092\u4f7f\u7528\u3059\u308b\u3068\u3001\u30af\u30a8\u30ea\u304c\u3088\u308a\u52b9\u7387\u7684\u304b\u3064\u78ba\u5b9f\u306b\u306a\u308a\u307e\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
\u30c6\u30fc\u30d6\u30eb\u5185\u306e null \u304c\u8a31\u5bb9\u3055\u308c\u3066\u3044\u308b\u5217\u306f\u3001\u30dd\u30a4\u30f3\u30bf\u307e\u305f\u306f sql.NullXXX
\u578b\u3092\u4f7f\u7528\u3057\u3066\u51e6\u7406\u3057\u307e\u3057\u3087\u3046\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
\u884c\u306e\u53cd\u5fa9\u51e6\u7406\u306e\u5f8c\u306b sql.Rows
\u306e Err
\u30e1\u30bd\u30c3\u30c9\u3092\u547c\u3073\u51fa\u3057\u3066\u3001\u6b21\u306e\u884c\u306e\u6e96\u5099\u4e2d\u306b\u30a8\u30e9\u30fc\u3092\u898b\u9003\u3057\u3066\u3044\u306a\u3044\u3053\u3068\u3092\u78ba\u8a8d\u3057\u307e\u3057\u3087\u3046\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#http-bodysqlrows-osfile-79","title":"\u4e00\u6642\u7684\u306a\u30ea\u30bd\u30fc\u30b9\uff08 HTTP body\u3001sql.Rows
\u3001\u304a\u3088\u3073 os.File
\uff09\u3092\u9589\u3058\u3066\u3044\u306a\u3044 (#79)","text":"\u8981\u7d04 \u30ea\u30fc\u30af\u3092\u907f\u3051\u308b\u305f\u3081\u306b\u3001 io.Closer
\u3092\u5b9f\u88c5\u3057\u3066\u3044\u308b\u3059\u3079\u3066\u306e\u69cb\u9020\u4f53\u3092\u6700\u5f8c\u306b\u306f\u9589\u3058\u307e\u3057\u3087\u3046\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#http-return-80","title":"HTTP \u30ea\u30af\u30a8\u30b9\u30c8\u306b\u5fdc\u7b54\u3057\u305f\u5f8c\u306e return \u6587\u3092\u5fd8\u308c\u3066\u3057\u307e\u3046 (#80)","text":"\u8981\u7d04HTTP \u30cf\u30f3\u30c9\u30e9\u306e\u5b9f\u88c5\u3067\u306e\u4e88\u60f3\u5916\u306e\u52d5\u4f5c\u3092\u907f\u3051\u308b\u305f\u3081\u3001http.Error
\u306e\u5f8c\u306b\u30cf\u30f3\u30c9\u30e9\u3092\u505c\u6b62\u3057\u305f\u3044\u5834\u5408\u306f\u3001return
\u6587\u3092\u5fd8\u308c\u306a\u3044\u3088\u3046\u306b\u3057\u3066\u304f\u3060\u3055\u3044\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#http-81","title":"\u6a19\u6e96\u306e HTTP \u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u3068\u30b5\u30fc\u30d0\u30fc\u3092\u4f7f\u7528\u3057\u3066\u3044\u308b (#81)","text":"\u8981\u7d04\u5b9f\u904b\u7528\u6c34\u6e96\u306e\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u6c42\u3081\u3066\u3044\u308b\u5834\u5408\u306f\u3001\u6a19\u6e96\u306e HTTP \u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u3068\u30b5\u30fc\u30d0\u30fc\u306e\u5b9f\u88c5\u3092\u4f7f\u7528\u3057\u306a\u3044\u3067\u304f\u3060\u3055\u3044\u3002\u3053\u308c\u3089\u306e\u5b9f\u88c5\u306b\u306f\u3001\u30bf\u30a4\u30e0\u30a2\u30a6\u30c8\u3084\u7a3c\u50cd\u74b0\u5883\u3067\u5fc5\u9808\u3067\u3042\u308b\u3079\u304d\u52d5\u4f5c\u304c\u6b20\u843d\u3057\u3066\u3044\u307e\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#_16","title":"\u30c6\u30b9\u30c8","text":""},{"location":"ja/#82","title":"\u30c6\u30b9\u30c8\u3092\u5206\u985e\u3057\u3066\u3044\u306a\u3044\uff08\u30d3\u30eb\u30c9\u30bf\u30b0\u3001\u74b0\u5883\u5909\u6570\u3001\u30b7\u30e7\u30fc\u30c8\u30e2\u30fc\u30c9\uff09 (#82)","text":"\u8981\u7d04\u30d3\u30eb\u30c9\u30d5\u30e9\u30b0\u3001\u74b0\u5883\u5909\u6570\u3001\u307e\u305f\u306f\u30b7\u30e7\u30fc\u30c8\u30e2\u30fc\u30c9\u3092\u4f7f\u7528\u3057\u3066\u30c6\u30b9\u30c8\u3092\u5206\u985e\u3059\u308b\u3068\u3001\u30c6\u30b9\u30c8\u30d7\u30ed\u30bb\u30b9\u304c\u3088\u308a\u52b9\u7387\u7684\u306b\u306a\u308a\u307e\u3059\u3002\u30d3\u30eb\u30c9\u30d5\u30e9\u30b0\u307e\u305f\u306f\u74b0\u5883\u5909\u6570\u3092\u4f7f\u7528\u3057\u3066\u30c6\u30b9\u30c8\u30ab\u30c6\u30b4\u30ea\uff08\u305f\u3068\u3048\u3070\u3001\u5358\u4f53\u30c6\u30b9\u30c8\u3068\u7d71\u5408\u30c6\u30b9\u30c8\uff09\u3092\u4f5c\u6210\u3057\u3001\u77ed\u671f\u9593\u306e\u30c6\u30b9\u30c8\u3068\u9577\u6642\u9593\u306e\u30c6\u30b9\u30c8\u3092\u533a\u5225\u3059\u308b\u3053\u3068\u3067\u3001\u5b9f\u884c\u3059\u308b\u30c6\u30b9\u30c8\u306e\u7a2e\u985e\u3092\u6c7a\u5b9a\u3067\u304d\u307e\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#-race-83","title":"-race
\u30d5\u30e9\u30b0\u3092\u6709\u52b9\u306b\u3057\u3066\u3044\u306a\u3044 (#83)","text":"\u8981\u7d04 \u4e26\u884c\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u4f5c\u6210\u3059\u308b\u5834\u5408\u306f\u3001 -race
\u30d5\u30e9\u30b0\u3092\u6709\u52b9\u306b\u3059\u308b\u3053\u3068\u3092\u5f37\u304f\u304a\u52e7\u3081\u3057\u307e\u3059\u3002\u305d\u3046\u3059\u308b\u3053\u3068\u3067\u3001\u30bd\u30d5\u30c8\u30a6\u30a7\u30a2\u306e\u30d0\u30b0\u306b\u3064\u306a\u304c\u308b\u53ef\u80fd\u6027\u306e\u3042\u308b\u6f5c\u5728\u7684\u306a\u30c7\u30fc\u30bf\u7af6\u5408\u3092\u767a\u898b\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002
-parallel
\u304a\u3088\u3073 -shuffle
\uff09\u3092\u4f7f\u7528\u3057\u3066\u3044\u306a\u3044 (#84)","text":"\u8981\u7d04 -parallel
\u30d5\u30e9\u30b0\u3092\u4f7f\u7528\u3059\u308b\u306e\u306f\u3001\u7279\u306b\u9577\u6642\u9593\u5b9f\u884c\u3055\u308c\u308b\u30c6\u30b9\u30c8\u3092\u9ad8\u901f\u5316\u3059\u308b\u306e\u306b\u52b9\u679c\u7684\u3067\u3059\u3002 -shuffle
\u30d5\u30e9\u30b0\u3092\u4f7f\u7528\u3059\u308b\u3068\u3001\u30c6\u30b9\u30c8\u30b9\u30a4\u30fc\u30c8\u304c\u30d0\u30b0\u3092\u96a0\u3059\u53ef\u80fd\u6027\u306e\u3042\u308b\u9593\u9055\u3063\u305f\u4eee\u5b9a\u306b\u4f9d\u5b58\u3057\u306a\u3044\u3088\u3046\u306b\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002
\u30c6\u30fc\u30d6\u30eb\u99c6\u52d5\u30c6\u30b9\u30c8\u306f\u3001\u30b3\u30fc\u30c9\u306e\u91cd\u8907\u3092\u9632\u304e\u3001\u5c06\u6765\u306e\u66f4\u65b0\u306e\u51e6\u7406\u3092\u5bb9\u6613\u306b\u3059\u308b\u305f\u3081\u306b\u3001\u4e00\u9023\u306e\u985e\u4f3c\u3057\u305f\u30c6\u30b9\u30c8\u3092\u30b0\u30eb\u30fc\u30d7\u5316\u3059\u308b\u52b9\u7387\u7684\u306a\u65b9\u6cd5\u3067\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#86","title":"\u5358\u4f53\u30c6\u30b9\u30c8\u3067\u306e\u30b9\u30ea\u30fc\u30d7 (#86)","text":"\u8981\u7d04\u30c6\u30b9\u30c8\u306e\u4e0d\u5b89\u5b9a\u3055\u3092\u306a\u304f\u3057\u3001\u3088\u308a\u5805\u7262\u306b\u3059\u308b\u305f\u3081\u306b\u3001\u540c\u671f\u3092\u4f7f\u7528\u3057\u3066\u30b9\u30ea\u30fc\u30d7\u3092\u56de\u907f\u3057\u307e\u3057\u3087\u3046\u3002\u540c\u671f\u304c\u4e0d\u53ef\u80fd\u306a\u5834\u5408\u306f\u3001\u30ea\u30c8\u30e9\u30a4\u624b\u6cd5\u3092\u691c\u8a0e\u3057\u3066\u304f\u3060\u3055\u3044\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#time-api-87","title":"time API \u3092\u52b9\u7387\u7684\u306b\u51e6\u7406\u3067\u304d\u3066\u3044\u306a\u3044 (#87)","text":"\u8981\u7d04time API \u3092\u4f7f\u7528\u3057\u3066\u95a2\u6570\u3092\u51e6\u7406\u3059\u308b\u65b9\u6cd5\u3092\u7406\u89e3\u3059\u308b\u3053\u3068\u3067\u3001\u30c6\u30b9\u30c8\u306e\u4e0d\u5b89\u5b9a\u3055\u3092\u8efd\u6e1b\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u96a0\u308c\u305f\u4f9d\u5b58\u95a2\u4fc2\u306e\u4e00\u90e8\u3068\u3057\u3066 time \u3092\u51e6\u7406\u3057\u305f\u308a\u3001\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u306b time \u3092\u63d0\u4f9b\u3059\u308b\u3088\u3046\u306b\u8981\u6c42\u3057\u305f\u308a\u3059\u308b\u306a\u3069\u3001\u6a19\u6e96\u7684\u306a\u624b\u6bb5\u3092\u5229\u7528\u3067\u304d\u307e\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#httptest-iotest-88","title":"\u30c6\u30b9\u30c8\u306b\u95a2\u3059\u308b\u30e6\u30fc\u30c6\u30a3\u30ea\u30c6\u30a3\u30d1\u30c3\u30b1\u30fc\u30b8\uff08httptest
\u304a\u3088\u3073 iotest
\uff09\u3092\u4f7f\u7528\u3057\u3066\u3044\u306a\u3044 (#88)","text":"httptest
\u30d1\u30c3\u30b1\u30fc\u30b8\u306f\u3001HTTP \u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u6271\u3046\u306e\u306b\u5f79\u7acb\u3061\u307e\u3059\u3002\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u3068\u30b5\u30fc\u30d0\u30fc\u306e\u4e21\u65b9\u3092\u30c6\u30b9\u30c8\u3059\u308b\u305f\u3081\u306e\u4e00\u9023\u306e\u30e6\u30fc\u30c6\u30a3\u30ea\u30c6\u30a3\u3092\u63d0\u4f9b\u3057\u307e\u3059\u3002\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
iotest
\u30d1\u30c3\u30b1\u30fc\u30b8\u306f\u3001io.Reader \u3092\u4f5c\u6210\u3057\u3001\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u30a8\u30e9\u30fc\u8010\u6027\u3092\u30c6\u30b9\u30c8\u3059\u308b\u306e\u306b\u5f79\u7acb\u3061\u307e\u3059\u3002\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#89","title":"\u4e0d\u6b63\u78ba\u306a\u30d9\u30f3\u30c1\u30de\u30fc\u30af\u306e\u4f5c\u6210 (#89)","text":"\u8981\u7d04\u30d9\u30f3\u30c1\u30de\u30fc\u30af\u306b\u3064\u3044\u3066
\u30bb\u30af\u30b7\u30e7\u30f3\u5168\u6587\u306f\u3053\u3061\u3089\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#go-90","title":"Go\u8a00\u8a9e\u306e\u30c6\u30b9\u30c8\u6a5f\u80fd\u3092\u3059\u3079\u3066\u8a66\u3057\u3066\u3044\u306a\u3044 (#90)","text":"\u30b3\u30fc\u30c9\u306e\u3069\u306e\u90e8\u5206\u306b\u6ce8\u610f\u304c\u5fc5\u8981\u304b\u3092\u3059\u3050\u306b\u78ba\u8a8d\u3059\u308b\u305f\u3081\u306b\u3001-coverprofile
\u30d5\u30e9\u30b0\u3092\u6307\u5b9a\u3057\u3066\u30b3\u30fc\u30c9\u30ab\u30d0\u30ec\u30c3\u30b8\u3092\u4f7f\u7528\u3057\u307e\u3057\u3087\u3046\u3002
\u5185\u90e8\u3067\u306f\u306a\u304f\u516c\u958b\u3055\u308c\u305f\u52d5\u4f5c\u306b\u7126\u70b9\u3092\u5f53\u3066\u305f\u30c6\u30b9\u30c8\u306e\u4f5c\u6210\u3092\u5f37\u5236\u3059\u308b\u305f\u3081\u306b\u3001\u5358\u4f53\u30c6\u30b9\u30c8\u306f\u5225\u3005\u306e\u30d1\u30c3\u30b1\u30fc\u30b8\u306b\u914d\u7f6e\u3057\u307e\u3057\u3087\u3046\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
\u5f93\u6765\u306e if err != nil
\u306e\u4ee3\u308f\u308a\u306b *testing.T
\u5909\u6570\u3092\u4f7f\u7528\u3057\u3066\u30a8\u30e9\u30fc\u3092\u51e6\u7406\u3059\u308b\u3068\u3001\u30b3\u30fc\u30c9\u304c\u77ed\u304f\u3001\u8aad\u307f\u3084\u3059\u304f\u306a\u308a\u307e\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
setup \u304a\u3088\u3073 teardown \u6a5f\u80fd\u3092\u5229\u7528\u3057\u3066\u3001\u7d71\u5408\u30c6\u30b9\u30c8\u306e\u5834\u5408\u306a\u3069\u3001\u8907\u96d1\u306a\u74b0\u5883\u3092\u69cb\u6210\u3067\u304d\u307e\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#community-mistake","title":"\u30d5\u30a1\u30b8\u30f3\u30b0\u3092\u4f7f\u7528\u3057\u3066\u3044\u306a\u3044\uff08community mistake\uff09","text":"\u8981\u7d04\u30d5\u30a1\u30b8\u30f3\u30b0\u306f\u3001\u8907\u96d1\u306a\u95a2\u6570\u3084\u30e1\u30bd\u30c3\u30c9\u3078\u306e\u30e9\u30f3\u30c0\u30e0\u306a\u3001\u4e88\u60f3\u5916\u306e\u3001\u307e\u305f\u306f\u4e0d\u6b63\u306a\u5165\u529b\u3092\u691c\u51fa\u3057\u3001\u8106\u5f31\u6027\u3001\u30d0\u30b0\u3001\u3055\u3089\u306b\u306f\u6f5c\u5728\u7684\u306a\u30af\u30e9\u30c3\u30b7\u30e5\u3092\u767a\u898b\u3059\u308b\u306e\u306b\u52b9\u7387\u7684\u3067\u3059\u3002
@jeromedoucet \u3055\u3093\u306e\u3054\u5354\u529b\u306b\u611f\u8b1d\u3044\u305f\u3057\u307e\u3059\u3002
"},{"location":"ja/#_17","title":"\u6700\u9069\u5316","text":""},{"location":"ja/#cpu-91","title":"CPU \u30ad\u30e3\u30c3\u30b7\u30e5\u3092\u7406\u89e3\u3057\u3066\u3044\u306a\u3044 (#91)","text":"L1 \u30ad\u30e3\u30c3\u30b7\u30e5\u306f\u30e1\u30a4\u30f3\u30e1\u30e2\u30ea\u3088\u308a\u3082\u7d04 50 \uff5e 100 \u500d\u9ad8\u901f\u3067\u3042\u308b\u305f\u3081\u3001CPU \u30d0\u30a6\u30f3\u30c9\u306e\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u6700\u9069\u5316\u3059\u308b\u306b\u306f\u3001CPU \u30ad\u30e3\u30c3\u30b7\u30e5\u306e\u4f7f\u7528\u65b9\u6cd5\u3092\u7406\u89e3\u3059\u308b\u3053\u3068\u304c\u91cd\u8981\u3067\u3059\u3002
\u30ad\u30e3\u30c3\u30b7\u30e5\u30e9\u30a4\u30f3\u306e\u6982\u5ff5\u3092\u610f\u8b58\u3059\u308b\u3053\u3068\u306f\u3001\u30c7\u30fc\u30bf\u96c6\u7d04\u578b\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3067\u30c7\u30fc\u30bf\u3092\u6574\u7406\u3059\u308b\u65b9\u6cd5\u3092\u7406\u89e3\u3059\u308b\u306e\u306b\u91cd\u8981\u3067\u3059\u3002CPU \u306f\u30e1\u30e2\u30ea\u3092\u30ef\u30fc\u30c9\u3054\u3068\u306b\u30d5\u30a7\u30c3\u30c1\u3057\u307e\u305b\u3093\u3002\u4ee3\u308f\u308a\u306b\u3001\u901a\u5e38\u306f\u30e1\u30e2\u30ea\u30d6\u30ed\u30c3\u30af\u3092 64 \u30d0\u30a4\u30c8\u306e\u30ad\u30e3\u30c3\u30b7\u30e5\u30e9\u30a4\u30f3\u306b\u30b3\u30d4\u30fc\u3057\u307e\u3059\u3002\u500b\u3005\u306e\u30ad\u30e3\u30c3\u30b7\u30e5\u30e9\u30a4\u30f3\u3092\u6700\u5927\u9650\u306b\u6d3b\u7528\u3059\u308b\u306b\u306f\u3001\u7a7a\u9593\u7684\u5c40\u6240\u6027\u3092\u5f37\u5236\u3057\u3066\u304f\u3060\u3055\u3044\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
CPU \u306b\u3068\u3063\u3066\u4e88\u6e2c\u53ef\u80fd\u306a\u30b3\u30fc\u30c9\u306b\u3059\u308b\u3053\u3068\u306f\u3001\u7279\u5b9a\u306e\u95a2\u6570\u3092\u6700\u9069\u5316\u3059\u308b\u52b9\u7387\u7684\u306a\u65b9\u6cd5\u3067\u3082\u3042\u308a\u307e\u3059\u3002\u305f\u3068\u3048\u3070\u3001\u30e6\u30cb\u30c3\u30c8\u307e\u305f\u306f\u5b9a\u6570\u30b9\u30c8\u30e9\u30a4\u30c9\u306f CPU \u306b\u3068\u3063\u3066\u4e88\u6e2c\u53ef\u80fd\u3067\u3059\u304c\u3001\u975e\u30e6\u30cb\u30c3\u30c8\u30b9\u30c8\u30e9\u30a4\u30c9\uff08\u9023\u7d50\u30ea\u30b9\u30c8\u306a\u3069\uff09\u306f\u4e88\u6e2c\u3067\u304d\u307e\u305b\u3093\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
\u30ad\u30e3\u30c3\u30b7\u30e5\u304c\u30d1\u30fc\u30c6\u30a3\u30b7\u30e7\u30f3\u5316\u3055\u308c\u3066\u3044\u308b\u3053\u3068\u3092\u8a8d\u8b58\u3059\u308b\u3053\u3068\u3067\u3001\u91cd\u5927\u306a\u30b9\u30c8\u30e9\u30a4\u30c9\u3092\u56de\u907f\u3057\u3001\u30ad\u30e3\u30c3\u30b7\u30e5\u306e\u3054\u304f\u4e00\u90e8\u306e\u307f\u3092\u4f7f\u7528\u3059\u308b\u3088\u3046\u306b\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002
"},{"location":"ja/#92","title":"\u8aa4\u3063\u305f\u5171\u6709\u3092\u5f15\u304d\u8d77\u3053\u3059\u4e26\u884c\u51e6\u7406(#92)","text":"\u8981\u7d04\u4e0b\u4f4d\u30ec\u30d9\u30eb\u306e CPU \u30ad\u30e3\u30c3\u30b7\u30e5\u304c\u3059\u3079\u3066\u306e\u30b3\u30a2\u3067\u5171\u6709\u3055\u308c\u308b\u308f\u3051\u3067\u306f\u306a\u3044\u3053\u3068\u3092\u77e5\u3063\u3066\u304a\u304f\u3068\u3001\u4e26\u884c\u51e6\u7406\u306b\u304a\u3051\u308b\u306e\u8aa4\u3063\u305f\u5171\u6709\u306a\u3069\u3067\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u3092\u4f4e\u4e0b\u3055\u305b\u3066\u3057\u307e\u3046\u3053\u3068\u3092\u56de\u907f\u3067\u304d\u307e\u3059\u3002\u30e1\u30e2\u30ea\u306e\u5171\u6709\u306f\u3042\u308a\u3048\u306a\u3044\u306e\u3067\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#93","title":"\u547d\u4ee4\u30ec\u30d9\u30eb\u306e\u4e26\u5217\u6027\u3092\u8003\u616e\u3057\u306a\u3044 (#93)","text":"\u8981\u7d04\u547d\u4ee4\u30ec\u30d9\u30eb\u306e\u4e26\u5217\u6027\uff08ILP\uff09\u3092\u4f7f\u7528\u3057\u3066\u30b3\u30fc\u30c9\u306e\u7279\u5b9a\u306e\u90e8\u5206\u3092\u6700\u9069\u5316\u3057\u3001CPU \u304c\u3067\u304d\u308b\u3060\u3051\u591a\u304f\u306e\u547d\u4ee4\u3092\u4e26\u5217\u5b9f\u884c\u3067\u304d\u308b\u3088\u3046\u306b\u3057\u307e\u3057\u3087\u3046\u3002\u4e3b\u306a\u624b\u9806\u306e 1 \u3064\u306b\u30c7\u30fc\u30bf\u30cf\u30b6\u30fc\u30c9\u306e\u7279\u5b9a\u304c\u3042\u308a\u307e\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#94","title":"\u30c7\u30fc\u30bf\u306e\u914d\u7f6e\u3092\u610f\u8b58\u3057\u3066\u3044\u306a\u3044 (#94)","text":"\u8981\u7d04Go\u8a00\u8a9e\u3067\u306f\u3001\u57fa\u672c\u578b\u306f\u5404\u3005\u306e\u30b5\u30a4\u30ba\u306b\u5408\u308f\u305b\u3066\u914d\u7f6e\u3055\u308c\u308b\u3053\u3068\u3092\u899a\u3048\u3066\u304a\u304f\u3053\u3068\u3067\u3001\u3042\u308a\u304c\u3061\u306a\u9593\u9055\u3044\u3092\u907f\u3051\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u305f\u3068\u3048\u3070\u3001\u69cb\u9020\u4f53\u306e\u30d5\u30a3\u30fc\u30eb\u30c9\u3092\u30b5\u30a4\u30ba\u3067\u964d\u9806\u306b\u518d\u7de8\u6210\u3059\u308b\u3068\u3001\u69cb\u9020\u4f53\u304c\u3088\u308a\u30b3\u30f3\u30d1\u30af\u30c8\u306b\u306a\u308b\uff08\u30e1\u30e2\u30ea\u5272\u308a\u5f53\u3066\u304c\u5c11\u306a\u304f\u306a\u308a\u3001\u7a7a\u9593\u7684\u5c40\u6240\u6027\u304c\u5411\u4e0a\u3059\u308b\uff09\u53ef\u80fd\u6027\u304c\u3042\u308b\u3053\u3068\u306b\u7559\u610f\u3057\u3066\u304f\u3060\u3055\u3044\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#95","title":"\u30d2\u30fc\u30d7\u3068\u30b9\u30bf\u30c3\u30af\u306e\u9055\u3044\u3092\u7406\u89e3\u3057\u3066\u3044\u306a\u3044 (#95)","text":"\u8981\u7d04\u30d2\u30fc\u30d7\u3068\u30b9\u30bf\u30c3\u30af\u306e\u57fa\u672c\u7684\u306a\u9055\u3044\u3092\u7406\u89e3\u3059\u308b\u3053\u3068\u3082\u3001Go \u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u6700\u9069\u5316\u3059\u308b\u969b\u306b\u306f\u5927\u5207\u3067\u3059\u3002\u30b9\u30bf\u30c3\u30af\u5272\u308a\u5f53\u3066\u306f\u5bb9\u6613\u306a\u306e\u306b\u5bfe\u3057\u3066\u3001\u30d2\u30fc\u30d7\u5272\u308a\u5f53\u3066\u306f\u9045\u304f\u3001\u30e1\u30e2\u30ea\u306e\u30af\u30ea\u30fc\u30f3\u30a2\u30c3\u30d7\u306b GC \u3092\u5229\u7528\u3057\u307e\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#api-syncpool-96","title":"\u5272\u308a\u5f53\u3066\u3092\u6e1b\u3089\u3059\u65b9\u6cd5\u304c\u308f\u304b\u3063\u3066\u3044\u306a\u3044\uff08 API \u306e\u5909\u66f4\u3001\u30b3\u30f3\u30d1\u30a4\u30e9\u306e\u6700\u9069\u5316\u3001\u304a\u3088\u3073sync.Pool
\uff09 (#96)","text":"\u8981\u7d04 \u5272\u308a\u5f53\u3066\u3092\u6e1b\u3089\u3059\u3053\u3068\u3082\u3001Go \u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u6700\u9069\u5316\u3059\u308b\u4e0a\u3067\u91cd\u8981\u3067\u3059\u3002\u3053\u308c\u306f\u3001\u5171\u6709\u3092\u9632\u3050\u305f\u3081\u306b API \u3092\u614e\u91cd\u306b\u8a2d\u8a08\u3059\u308b\u3001\u4e00\u822c\u7684\u306a Go \u30b3\u30f3\u30d1\u30a4\u30e9\u306e\u6700\u9069\u5316\u3092\u7406\u89e3\u3059\u308b\u3001sync.Pool
\u3092\u4f7f\u7528\u3059\u308b\u306a\u3069\u3001\u3055\u307e\u3056\u307e\u306a\u65b9\u6cd5\u3067\u884c\u3046\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#97","title":"\u30a4\u30f3\u30e9\u30a4\u30f3\u5c55\u958b\u3092\u3057\u3066\u3044\u306a\u3044 (#97)","text":"\u8981\u7d04\u30d5\u30a1\u30b9\u30c8\u30d1\u30b9\u306e\u30a4\u30f3\u30e9\u30a4\u30f3\u5316\u624b\u6cd5\u3092\u4f7f\u7528\u3057\u3066\u3001\u95a2\u6570\u306e\u547c\u3073\u51fa\u3057\u306b\u304b\u304b\u308b\u511f\u5374\u6642\u9593\u3092\u52b9\u7387\u7684\u306b\u524a\u6e1b\u3057\u307e\u3057\u3087\u3046\u3002
"},{"location":"ja/#go-98","title":"Go\u8a00\u8a9e\u306e\u8a3a\u65ad\u30c4\u30fc\u30eb\u3092\u5229\u7528\u3057\u3066\u3044\u306a\u3044 (#98)","text":"\u8981\u7d04\u30d7\u30ed\u30d5\u30a1\u30a4\u30ea\u30f3\u30b0\u3068\u5b9f\u884c\u30c8\u30ec\u30fc\u30b5\u3092\u5229\u7528\u3057\u3066\u3001\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u3068\u6700\u9069\u5316\u3059\u3079\u304d\u90e8\u5206\u306b\u3064\u3044\u3066\u7406\u89e3\u3057\u307e\u3057\u3087\u3046\u3002
\u30bb\u30af\u30b7\u30e7\u30f3\u5168\u6587\u306f\u3053\u3061\u3089\u3002
"},{"location":"ja/#gc-99","title":"GC \u306e\u4ed5\u7d44\u307f\u3092\u7406\u89e3\u3057\u3066\u3044\u306a\u3044 (#99)","text":"\u8981\u7d04GC \u306e\u8abf\u6574\u65b9\u6cd5\u3092\u7406\u89e3\u3059\u308b\u3068\u3001\u7a81\u7136\u306e\u8ca0\u8377\u306e\u5897\u52a0\u3092\u3088\u308a\u52b9\u7387\u7684\u306b\u51e6\u7406\u3067\u304d\u308b\u306a\u3069\u3001\u3055\u307e\u3056\u307e\u306a\u6069\u6075\u304c\u5f97\u3089\u308c\u307e\u3059\u3002
"},{"location":"ja/#docker-kubernetes-go-100","title":"Docker \u3068 Kubernetes \u4e0a\u3067Go\u8a00\u8a9e\u3092\u5b9f\u884c\u3059\u308b\u3053\u3068\u306e\u5f71\u97ff\u3092\u7406\u89e3\u3057\u3066\u3044\u306a\u3044 (#100)","text":"\u8981\u7d04Docker \u3068 Kubernetes \u306b\u30c7\u30d7\u30ed\u30a4\u3059\u308b\u969b\u306e CPU \u30b9\u30ed\u30c3\u30c8\u30ea\u30f3\u30b0\u3092\u56de\u907f\u3059\u308b\u306b\u306f\u3001Go\u8a00\u8a9e\u304c CFS \u5bfe\u5fdc\u3067\u306f\u306a\u3044\u3053\u3068\u306b\u7559\u610f\u3057\u3066\u304f\u3060\u3055\u3044\u3002
"},{"location":"zh/","title":"100\u4e2aGo\u5e38\u89c1\u9519\u8bef\u53ca\u5982\u4f55\u907f\u514d","text":"JobsIs your company hiring? Sponsor the Chinese version of this repository and let a significant audience of Go developers (~1k unique visitors per week) know about your opportunities in this section.
"},{"location":"zh/#_1","title":"\u4ee3\u7801\u53ca\u5de5\u7a0b\u7ec4\u7ec7","text":""},{"location":"zh/#1","title":"\u610f\u5916\u7684\u53d8\u91cf\u9690\u85cf (#1)","text":"\u907f\u514d\u53d8\u91cf\u9690\u85cf\uff08\u5916\u90e8\u4f5c\u7528\u57df\u53d8\u91cf\u88ab\u5185\u90e8\u4f5c\u7528\u57df\u540c\u540d\u53d8\u91cf\u9690\u85cf\uff09\uff0c\u6709\u52a9\u4e8e\u907f\u514d\u53d8\u91cf\u5f15\u7528\u9519\u8bef\uff0c\u6709\u52a9\u4e8e\u4ed6\u4eba\u9605\u8bfb\u7406\u89e3\u3002
"},{"location":"zh/#2","title":"\u4e0d\u5fc5\u8981\u7684\u4ee3\u7801\u5d4c\u5957 (#2)","text":"\u907f\u514d\u4e0d\u5fc5\u8981\u7684\u3001\u8fc7\u591a\u7684\u5d4c\u5957\u5c42\u6b21\uff0c\u5e76\u4e14\u8ba9\u6b63\u5e38\u4ee3\u7801\u8def\u5f84\u5c3d\u91cf\u5de6\u5bf9\u9f50\uff08\u800c\u4e0d\u662f\u653e\u5728\u5206\u652f\u8def\u5f84\u4e2d\uff09\uff0c\u6709\u52a9\u4e8e\u6784\u5efa\u53ef\u8bfb\u6027\u66f4\u597d\u7684\u4ee3\u7801\u3002
"},{"location":"zh/#init-3","title":"\u8bef\u7528init\u51fd\u6570 (#3)","text":"\u521d\u59cb\u5316\u53d8\u91cf\u65f6\uff0c\u8bf7\u8bb0\u4f4f init \u51fd\u6570\u5177\u6709\u6709\u9650\u7684\u9519\u8bef\u5904\u7406\u80fd\u529b\uff0c\u5e76\u4e14\u4f1a\u4f7f\u72b6\u6001\u5904\u7406\u548c\u6d4b\u8bd5\u53d8\u5f97\u66f4\u52a0\u590d\u6742\u3002\u5728\u5927\u591a\u6570\u60c5\u51b5\u4e0b\uff0c\u521d\u59cb\u5316\u5e94\u8be5\u4f5c\u4e3a\u7279\u5b9a\u51fd\u6570\u6765\u5904\u7406\u3002
"},{"location":"zh/#getterssetters-4","title":"\u6ee5\u7528getters/setters (#4)","text":"\u5728Go\u8bed\u8a00\u4e2d\uff0c\u5f3a\u5236\u4f7f\u7528getter\u548csetter\u65b9\u6cd5\u5e76\u4e0d\u7b26\u5408Go\u60ef\u4f8b\u3002\u5728\u5b9e\u8df5\u4e2d\uff0c\u5e94\u8be5\u627e\u5230\u6548\u7387\u548c\u76f2\u76ee\u9075\u5faa\u67d0\u4e9b\u60ef\u7528\u6cd5\u4e4b\u95f4\u7684\u5e73\u8861\u70b9\u3002
"},{"location":"zh/#5","title":"\u63a5\u53e3\u6c61\u67d3 (#5)","text":"\u62bd\u8c61\u5e94\u8be5\u88ab\u53d1\u73b0\uff0c\u800c\u4e0d\u662f\u88ab\u521b\u9020\u3002\u4e3a\u4e86\u907f\u514d\u4e0d\u5fc5\u8981\u7684\u590d\u6742\u6027\uff0c\u9700\u8981\u65f6\u624d\u521b\u5efa\u63a5\u53e3\uff0c\u800c\u4e0d\u662f\u9884\u89c1\u5230\u9700\u8981\u5b83\uff0c\u6216\u8005\u81f3\u5c11\u53ef\u4ee5\u8bc1\u660e\u8fd9\u79cd\u62bd\u8c61\u662f\u6709\u4ef7\u503c\u7684\u3002
"},{"location":"zh/#6","title":"\u5c06\u63a5\u53e3\u5b9a\u4e49\u5728\u5b9e\u73b0\u65b9\u4e00\u4fa7 (#6)","text":"\u5c06\u63a5\u53e3\u4fdd\u7559\u5728\u5f15\u7528\u65b9\u4e00\u4fa7\uff08\u800c\u4e0d\u662f\u5b9e\u73b0\u65b9\u4e00\u4fa7\uff09\u53ef\u4ee5\u907f\u514d\u4e0d\u5fc5\u8981\u7684\u62bd\u8c61\u3002
"},{"location":"zh/#7","title":"\u5c06\u63a5\u53e3\u4f5c\u4e3a\u8fd4\u56de\u503c (#7)","text":"\u4e3a\u4e86\u907f\u514d\u5728\u7075\u6d3b\u6027\u65b9\u9762\u53d7\u5230\u9650\u5236\uff0c\u5927\u591a\u6570\u60c5\u51b5\u4e0b\u51fd\u6570\u4e0d\u5e94\u8be5\u8fd4\u56de\u63a5\u53e3\uff0c\u800c\u5e94\u8be5\u8fd4\u56de\u5177\u4f53\u7684\u5b9e\u73b0\u3002\u76f8\u53cd\uff0c\u51fd\u6570\u5e94\u8be5\u5c3d\u53ef\u80fd\u5730\u4f7f\u7528\u63a5\u53e3\u4f5c\u4e3a\u53c2\u6570\u3002
"},{"location":"zh/#any-8","title":"any
\u6ca1\u4f20\u9012\u4efb\u4f55\u4fe1\u606f (#8)","text":"\u53ea\u6709\u5728\u9700\u8981\u63a5\u53d7\u6216\u8fd4\u56de\u4efb\u610f\u7c7b\u578b\u65f6\uff0c\u624d\u4f7f\u7528 any
\uff0c\u4f8b\u5982 json.Marshal
\u3002\u5176\u4ed6\u60c5\u51b5\u4e0b\uff0c\u56e0\u4e3a any
\u4e0d\u63d0\u4f9b\u6709\u610f\u4e49\u7684\u4fe1\u606f\uff0c\u53ef\u80fd\u4f1a\u5bfc\u81f4\u7f16\u8bd1\u65f6\u95ee\u9898\uff0c\u5982\u5141\u8bb8\u8c03\u7528\u8005\u8c03\u7528\u65b9\u6cd5\u5904\u7406\u4efb\u610f\u7c7b\u578b\u6570\u636e\u3002
\u4f7f\u7528\u6cdb\u578b\uff0c\u53ef\u4ee5\u901a\u8fc7\u7c7b\u578b\u53c2\u6570\u5206\u79bb\u5177\u4f53\u7684\u6570\u636e\u7c7b\u578b\u548c\u884c\u4e3a\uff0c\u907f\u514d\u5199\u5f88\u591a\u91cd\u590d\u5ea6\u5f88\u9ad8\u7684\u4ee3\u7801\u3002\u7136\u800c\uff0c\u4e0d\u8981\u8fc7\u65e9\u5730\u4f7f\u7528\u6cdb\u578b\u3001\u7c7b\u578b\u53c2\u6570\uff0c\u53ea\u6709\u5728\u4f60\u770b\u5230\u771f\u6b63\u9700\u8981\u65f6\u624d\u4f7f\u7528\u3002\u5426\u5219\uff0c\u5b83\u4eec\u4f1a\u5f15\u5165\u4e0d\u5fc5\u8981\u7684\u62bd\u8c61\u548c\u590d\u6742\u6027\u3002
"},{"location":"zh/#10","title":"\u672a\u610f\u8bc6\u5230\u7c7b\u578b\u5d4c\u5957\u7684\u53ef\u80fd\u95ee\u9898 (#10)","text":"\u4f7f\u7528\u7c7b\u578b\u5d4c\u5957\u4e5f\u53ef\u4ee5\u907f\u514d\u5199\u4e00\u4e9b\u91cd\u590d\u4ee3\u7801\uff0c\u7136\u800c\uff0c\u5728\u4f7f\u7528\u65f6\u9700\u8981\u786e\u4fdd\u4e0d\u4f1a\u5bfc\u81f4\u4e0d\u5408\u7406\u7684\u53ef\u89c1\u6027\u95ee\u9898\uff0c\u6bd4\u5982\u6709\u4e9b\u5b57\u6bb5\u5e94\u8be5\u5bf9\u5916\u9690\u85cf\u4e0d\u5e94\u8be5\u88ab\u66b4\u6f0f\u3002
"},{"location":"zh/#function-option-11","title":"\u4e0d\u4f7f\u7528function option\u6a21\u5f0f (#11)","text":"\u4e3a\u4e86\u8bbe\u8ba1\u5e76\u63d0\u4f9b\u66f4\u53cb\u597d\u7684API\uff08\u53ef\u9009\u53c2\u6570\uff09\uff0c\u4e3a\u4e86\u66f4\u597d\u5730\u5904\u7406\u9009\u9879\uff0c\u5e94\u8be5\u4f7f\u7528function option\u6a21\u5f0f\u3002
"},{"location":"zh/#12","title":"\u5de5\u7a0b\u7ec4\u7ec7\u4e0d\u5408\u7406 (\u5de5\u7a0b\u7ed3\u6784\u548c\u5305\u7684\u7ec4\u7ec7) (#12)","text":"\u9075\u5faa\u50cf project-layout \u7684\u5efa\u8bae\u6765\u7ec4\u7ec7Go\u5de5\u7a0b\u662f\u4e00\u4e2a\u4e0d\u9519\u7684\u65b9\u6cd5\uff0c\u7279\u522b\u662f\u4f60\u6b63\u5728\u5bfb\u627e\u4e00\u4e9b\u7c7b\u4f3c\u7684\u7ecf\u9a8c\u3001\u60ef\u4f8b\u6765\u7ec4\u7ec7\u4e00\u4e2a\u65b0\u7684Go\u5de5\u7a0b\u7684\u65f6\u5019\u3002
"},{"location":"zh/#13","title":"\u521b\u5efa\u5de5\u5177\u5305 (#13)","text":"\u547d\u540d\u662f\u8f6f\u4ef6\u8bbe\u8ba1\u5f00\u53d1\u4e2d\u975e\u5e38\u91cd\u8981\u7684\u4e00\u4e2a\u90e8\u5206\uff0c\u521b\u5efa\u4e00\u4e9b\u540d\u5982 common
\u3001util
\u3001shared
\u4e4b\u7c7b\u7684\u5305\u540d\u5e76\u4e0d\u4f1a\u7ed9\u8bfb\u8005\u5e26\u6765\u592a\u5927\u4ef7\u503c\uff0c\u5e94\u8be5\u5c06\u8fd9\u4e9b\u5305\u540d\u91cd\u6784\u4e3a\u66f4\u6e05\u6670\u3001\u66f4\u805a\u7126\u7684\u5305\u540d\u3002
\u4e3a\u4e86\u907f\u514d\u53d8\u91cf\u540d\u548c\u5305\u540d\u4e4b\u95f4\u7684\u51b2\u7a81\uff0c\u5bfc\u81f4\u6df7\u6dc6\u6216\u751a\u81f3\u9519\u8bef\uff0c\u5e94\u4e3a\u6bcf\u4e2a\u53d8\u91cf\u548c\u5305\u4f7f\u7528\u552f\u4e00\u7684\u540d\u79f0\u3002\u5982\u679c\u8fd9\u4e0d\u53ef\u884c\uff0c\u53ef\u4ee5\u8003\u8651\u4f7f\u7528\u5bfc\u5165\u522b\u540d import importAlias 'importPath'
\uff0c\u4ee5\u533a\u5206\u5305\u540d\u548c\u53d8\u91cf\u540d\uff0c\u6216\u8005\u8003\u8651\u4e00\u4e2a\u66f4\u597d\u7684\u53d8\u91cf\u540d\u3002
\u4e3a\u4e86\u8ba9\u4f7f\u7528\u65b9\u3001\u7ef4\u62a4\u4eba\u5458\u80fd\u66f4\u6e05\u6670\u5730\u4e86\u89e3\u4f60\u7684\u4ee3\u7801\u7684\u610f\u56fe\uff0c\u5bfc\u51fa\u7684\u5143\u7d20\uff08\u51fd\u6570\u3001\u7c7b\u578b\u3001\u5b57\u6bb5\uff09\u9700\u8981\u6dfb\u52a0godoc\u6ce8\u91ca\u3002
"},{"location":"zh/#linters-16","title":"\u4e0d\u4f7f\u7528linters\u68c0\u67e5 (#16)","text":"\u4e3a\u4e86\u6539\u5584\u4ee3\u7801\u8d28\u91cf\u3001\u6574\u4f53\u4ee3\u7801\u7684\u4e00\u81f4\u6027\uff0c\u5e94\u8be5\u4f7f\u7528linters\u3001formatters\u3002
"},{"location":"zh/#_2","title":"\u6570\u636e\u7c7b\u578b","text":""},{"location":"zh/#17","title":"\u516b\u8fdb\u5236\u5b57\u9762\u91cf\u5f15\u53d1\u7684\u56f0\u60d1 (#17)","text":"\u5728\u9605\u8bfb\u73b0\u6709\u4ee3\u7801\u65f6\uff0c\u8bf7\u8bb0\u4f4f\u4ee5 0 \u5f00\u5934\u7684\u6574\u6570\u5b57\u9762\u91cf\u662f\u516b\u8fdb\u5236\u6570\u3002\u6b64\u5916\uff0c\u4e3a\u4e86\u63d0\u9ad8\u53ef\u8bfb\u6027\uff0c\u53ef\u4ee5\u901a\u8fc7\u5728\u524d\u9762\u52a0\u4e0a 0o \u6765\u663e\u5f0f\u5730\u8868\u793a\u516b\u8fdb\u5236\u6574\u6570\u3002
"},{"location":"zh/#18","title":"\u672a\u6ce8\u610f\u53ef\u80fd\u7684\u6574\u6570\u6ea2\u51fa (#18)","text":"\u5728 Go \u4e2d\u6574\u6570\u4e0a\u6ea2\u51fa\u548c\u4e0b\u6ea2\u662f\u9759\u9ed8\u5904\u7406\u7684\uff0c\u6240\u4ee5\u4f60\u53ef\u4ee5\u5b9e\u73b0\u81ea\u5df1\u7684\u51fd\u6570\u6765\u6355\u83b7\u5b83\u4eec\u3002
"},{"location":"zh/#19","title":"\u6ca1\u6709\u900f\u5f7b\u7406\u89e3\u6d6e\u70b9\u6570 (#19)","text":"\u6bd4\u8f83\u6d6e\u70b9\u6570\u65f6\uff0c\u901a\u8fc7\u6bd4\u8f83\u4e8c\u8005\u7684delta\u503c\u662f\u5426\u4ecb\u4e8e\u4e00\u5b9a\u7684\u8303\u56f4\u5185\uff0c\u80fd\u8ba9\u4f60\u5199\u51fa\u53ef\u79fb\u690d\u6027\u66f4\u597d\u7684\u4ee3\u7801\u3002
\u5728\u8fdb\u884c\u52a0\u6cd5\u6216\u51cf\u6cd5\u65f6\uff0c\u5c06\u5177\u6709\u76f8\u4f3c\u6570\u91cf\u7ea7\u7684\u64cd\u4f5c\u5206\u6210\u540c\u4e00\u7ec4\u4ee5\u63d0\u9ad8\u7cbe\u5ea6 (\u8fc7\u65e9\u6307\u6570\u5bf9\u9f50\u4e22\u5931\u7cbe\u5ea6)\u3002\u6b64\u5916\uff0c\u5728\u8fdb\u884c\u52a0\u6cd5\u548c\u51cf\u6cd5\u4e4b\u524d\uff0c\u5e94\u5148\u8fdb\u884c\u4e58\u6cd5\u548c\u9664\u6cd5 (\u52a0\u51cf\u6cd5\u8bef\u5dee\u4f1a\u88ab\u4e58\u9664\u653e\u5927)\u3002
"},{"location":"zh/#slice-20","title":"\u4e0d\u7406\u89e3slice\u7684\u957f\u5ea6\u548c\u5bb9\u91cf (#20)","text":"\u7406\u89e3slice\u7684\u957f\u5ea6\u548c\u5bb9\u91cf\u7684\u533a\u522b\uff0c\u662f\u4e00\u4e2aGo\u5f00\u53d1\u8005\u7684\u6838\u5fc3\u77e5\u8bc6\u70b9\u4e4b\u4e00\u3002slice\u7684\u957f\u5ea6\u6307\u7684\u662fslice\u5df2\u7ecf\u5b58\u50a8\u7684\u5143\u7d20\u7684\u6570\u91cf\uff0c\u800c\u5bb9\u91cf\u6307\u7684\u662fslice\u5f53\u524d\u5e95\u5c42\u5f00\u8f9f\u7684\u6570\u7ec4\u6700\u591a\u80fd\u5bb9\u7eb3\u7684\u5143\u7d20\u7684\u6570\u91cf\u3002
"},{"location":"zh/#slice-21","title":"\u4e0d\u9ad8\u6548\u7684slice\u521d\u59cb\u5316 (#21)","text":"\u5f53\u521b\u5efa\u4e00\u4e2aslice\u65f6\uff0c\u5982\u679c\u5176\u957f\u5ea6\u53ef\u4ee5\u9884\u5148\u786e\u5b9a\uff0c\u90a3\u4e48\u53ef\u4ee5\u5728\u5b9a\u4e49\u65f6\u6307\u5b9a\u5b83\u7684\u957f\u5ea6\u548c\u5bb9\u91cf\u3002\u8fd9\u53ef\u4ee5\u6539\u5584\u540e\u671fappend\u65f6\u4e00\u6b21\u6216\u8005\u591a\u6b21\u7684\u5185\u5b58\u5206\u914d\u64cd\u4f5c\uff0c\u4ece\u800c\u6539\u5584\u6027\u80fd\u3002\u5bf9\u4e8emap\u7684\u521d\u59cb\u5316\u4e5f\u662f\u8fd9\u6837\u7684\u3002
"},{"location":"zh/#nilslice-22","title":"\u56f0\u60d1\u4e8enil\u548c\u7a7aslice (#22)","text":"\u4e3a\u4e86\u907f\u514d\u5e38\u89c1\u7684\u5bf9nil\u548cempty slice\u5904\u7406\u884c\u4e3a\u7684\u6df7\u6dc6\uff0c\u4f8b\u5982\u5728\u4f7f\u7528 encoding/json \u6216 reflect \u5305\u65f6\uff0c\u4f60\u9700\u8981\u7406\u89e3 nil \u548c empty slice\u7684\u533a\u522b\u3002\u4e24\u8005\u90fd\u662f\u957f\u5ea6\u4e3a\u96f6\u3001\u5bb9\u91cf\u4e3a\u96f6\u7684\u5207\u7247\uff0c\u4f46\u662f nil \u5207\u7247\u4e0d\u9700\u8981\u5206\u914d\u5185\u5b58\u3002
"},{"location":"zh/#slice-23","title":"\u6ca1\u6709\u9002\u5f53\u68c0\u67e5slice\u662f\u5426\u4e3a\u7a7a (#23)","text":"\u68c0\u67e5\u4e00\u4e2aslice\u7684\u662f\u5426\u5305\u542b\u4efb\u4f55\u5143\u7d20\uff0c\u53ef\u4ee5\u68c0\u67e5\u5176\u957f\u5ea6\uff0c\u4e0d\u7ba1slice\u662fnil\u8fd8\u662fempty\uff0c\u68c0\u67e5\u957f\u5ea6\u90fd\u662f\u6709\u6548\u7684\u3002\u8fd9\u4e2a\u68c0\u67e5\u65b9\u6cd5\u4e5f\u9002\u7528\u4e8emap\u3002
\u4e3a\u4e86\u8bbe\u8ba1\u66f4\u660e\u786e\u7684API\uff0cAPI\u4e0d\u5e94\u533a\u5206nil\u548c\u7a7a\u5207\u7247\u3002
"},{"location":"zh/#slice-24","title":"\u6ca1\u6709\u6b63\u786e\u62f7\u8d1dslice (#24)","text":"\u4f7f\u7528 copy
\u62f7\u8d1d\u4e00\u4e2aslice\u5143\u7d20\u5230\u53e6\u4e00\u4e2aslice\u65f6\uff0c\u9700\u8981\u8bb0\u5f97\uff0c\u5b9e\u9645\u62f7\u8d1d\u7684\u5143\u7d20\u6570\u91cf\u662f\u4e8c\u8005slice\u957f\u5ea6\u4e2d\u7684\u8f83\u5c0f\u503c\u3002
\u5982\u679c\u4e24\u4e2a\u4e0d\u540c\u7684\u51fd\u6570\u64cd\u4f5c\u7684slice\u590d\u7528\u4e86\u76f8\u540c\u7684\u5e95\u5c42\u6570\u7ec4\uff0c\u5b83\u4eec\u5bf9slice\u6267\u884cappend\u64cd\u4f5c\u65f6\u53ef\u80fd\u4f1a\u4ea7\u751f\u51b2\u7a81\u3002\u4f7f\u7528copy\u6765\u5b8c\u6574\u590d\u5236\u4e00\u4e2aslice\u6216\u8005\u4f7f\u7528\u5b8c\u6574\u7684slice\u8868\u8fbe\u5f0f[low:high:max]\u9650\u5236\u6700\u5927\u5bb9\u91cf\uff0c\u6709\u52a9\u4e8e\u907f\u514d\u4ea7\u751f\u51b2\u7a81\u3002\u5f53\u60f3\u5bf9\u4e00\u4e2a\u5927slice\u8fdb\u884cshrink\u64cd\u4f5c\u65f6\uff0c\u4e24\u79cd\u65b9\u5f0f\u4e2d\uff0c\u53ea\u6709copy\u624d\u53ef\u4ee5\u907f\u514d\u5185\u5b58\u6cc4\u6f0f\u3002
"},{"location":"zh/#slice-26","title":"slice\u548c\u5185\u5b58\u6cc4\u6f0f (#26)","text":"\u5bf9\u4e8eslice\u5143\u7d20\u4e3a\u6307\u9488\uff0c\u6216\u8005slice\u5143\u7d20\u4e3astruct\u4f46\u662f\u8be5struct\u542b\u6709\u6307\u9488\u5b57\u6bb5\uff0c\u5f53\u901a\u8fc7slice[low:high]\u64cd\u4f5c\u53d6subslice\u65f6\uff0c\u5bf9\u4e8e\u90a3\u4e9b\u4e0d\u53ef\u8bbf\u95ee\u7684\u5143\u7d20\u53ef\u4ee5\u663e\u793a\u8bbe\u7f6e\u4e3anil\u6765\u907f\u514d\u5185\u5b58\u6cc4\u9732\u3002
"},{"location":"zh/#map-27","title":"\u4e0d\u9ad8\u6548\u7684map\u521d\u59cb\u5316 (#27)","text":"\u89c1 #21.
"},{"location":"zh/#map-28","title":"map\u548c\u5185\u5b58\u6cc4\u6f0f (#28)","text":"\u4e00\u4e2amap\u7684buckets\u5360\u7528\u7684\u5185\u5b58\u53ea\u4f1a\u589e\u957f\uff0c\u4e0d\u4f1a\u7f29\u51cf\u3002\u56e0\u6b64\uff0c\u5982\u679c\u5b83\u5bfc\u81f4\u4e86\u4e00\u4e9b\u5185\u5b58\u5360\u7528\u7684\u95ee\u9898\uff0c\u4f60\u9700\u8981\u5c1d\u8bd5\u4e0d\u540c\u7684\u9009\u9879\u6765\u89e3\u51b3\uff0c\u6bd4\u5982\u91cd\u65b0\u521b\u5efa\u4e00\u4e2amap\u4ee3\u66ff\u539f\u6765\u7684\uff08\u539f\u6765\u7684map\u4f1a\u88abGC\u6389\uff09\uff0c\u6216\u8005map[keyType]valueType\u4e2d\u7684valueType\u4f7f\u7528\u6307\u9488\u4ee3\u66ff\u957f\u5ea6\u56fa\u5b9a\u7684\u6570\u7ec4\u6216\u8005sliceHeader\u6765\u7f13\u89e3\u8fc7\u591a\u7684\u5185\u5b58\u5360\u7528\u3002
"},{"location":"zh/#29","title":"\u4e0d\u6b63\u786e\u7684\u503c\u6bd4\u8f83 (#29)","text":"Go\u4e2d\u6bd4\u8f83\u4e24\u4e2a\u7c7b\u578b\u503c\u65f6\uff0c\u5982\u679c\u662f\u53ef\u6bd4\u8f83\u7c7b\u578b\uff0c\u90a3\u4e48\u53ef\u4ee5\u4f7f\u7528 ==
\u6216\u8005 !=
\u8fd0\u7b97\u7b26\u8fdb\u884c\u6bd4\u8f83\uff0c\u6bd4\u5982\uff1abooleans\u3001numerals\u3001strings\u3001pointers\u3001channels\uff0c\u4ee5\u53ca\u5b57\u6bb5\u5168\u90e8\u662f\u53ef\u6bd4\u8f83\u7c7b\u578b\u7684structs\u3002\u5176\u4ed6\u60c5\u51b5\u4e0b\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528 reflect.DeepEqual
\u6765\u6bd4\u8f83\uff0c\u7528\u53cd\u5c04\u7684\u8bdd\u4f1a\u727a\u7272\u4e00\u70b9\u6027\u80fd\uff0c\u4e5f\u53ef\u4ee5\u4f7f\u7528\u81ea\u5b9a\u4e49\u7684\u5b9e\u73b0\u548c\u5176\u4ed6\u5e93\u6765\u5b8c\u6210\u3002
range
\u5faa\u73af\u53d8\u91cf\u662f\u4e00\u4e2a\u62f7\u8d1d (#30)","text":"range
\u5faa\u73af\u4e2d\u7684\u5faa\u73af\u53d8\u91cf\u662f\u904d\u5386\u5bb9\u5668\u4e2d\u5143\u7d20\u503c\u7684\u4e00\u4e2a\u62f7\u8d1d\u3002\u56e0\u6b64\uff0c\u5982\u679c\u5143\u7d20\u503c\u662f\u4e00\u4e2astruct\u5e76\u4e14\u60f3\u5728 range
\u4e2d\u4fee\u6539\u5b83\uff0c\u53ef\u4ee5\u901a\u8fc7\u7d22\u5f15\u503c\u6765\u8bbf\u95ee\u5e76\u4fee\u6539\u5b83\uff0c\u6216\u8005\u4f7f\u7528\u7ecf\u5178\u7684for\u5faa\u73af+\u7d22\u5f15\u503c\u7684\u5199\u6cd5\uff08\u9664\u975e\u904d\u5386\u7684\u5143\u7d20\u662f\u4e00\u4e2a\u6307\u9488\uff09\u3002
range
\u5faa\u73af\u4e2d\u8fed\u4ee3\u76ee\u6807\u503c\u7684\u8ba1\u7b97\u65b9\u5f0f (channels \u548c arrays) (#31)","text":"\u4f20\u9012\u7ed9 range
\u64cd\u4f5c\u7684\u8fed\u4ee3\u76ee\u6807\u5bf9\u5e94\u7684\u8868\u8fbe\u5f0f\u7684\u503c\uff0c\u53ea\u4f1a\u5728\u5faa\u73af\u6267\u884c\u524d\u88ab\u8ba1\u7b97\u4e00\u6b21\uff0c\u7406\u89e3\u8fd9\u4e2a\u6709\u52a9\u4e8e\u907f\u514d\u72af\u4e00\u4e9b\u5e38\u89c1\u7684\u9519\u8bef\uff0c\u4f8b\u5982\u4e0d\u9ad8\u6548\u7684channel\u8d4b\u503c\u64cd\u4f5c\u3001slice\u8fed\u4ee3\u64cd\u4f5c\u3002
range
\u5faa\u73af\u4e2d\u6307\u9488\u5143\u7d20\u7684\u5f71\u54cd range
loops (#32)","text":"\u8fd9\u91cc\u5176\u5b9e\u5f3a\u8c03\u7684\u662f range
\u8fed\u4ee3\u8fc7\u7a0b\u4e2d\uff0c\u8fed\u4ee3\u53d8\u91cf\u5b9e\u9645\u4e0a\u662f\u4e00\u4e2a\u62f7\u8d1d\uff0c\u5047\u8bbe\u7ed9\u53e6\u5916\u4e00\u4e2a\u5bb9\u5668\u5143\u7d20\uff08\u6307\u9488\u7c7b\u578b\uff09\u8d4b\u503c\uff0c\u4e14\u9700\u8981\u5bf9\u8fed\u4ee3\u53d8\u91cf\u53d6\u5730\u5740\u8f6c\u6362\u6210\u6307\u9488\u518d\u8d4b\u503c\u7684\u8bdd\uff0c\u8fd9\u91cc\u6f5c\u85cf\u7740\u4e00\u4e2a\u9519\u8bef\uff0c\u5c31\u662ffor\u5faa\u73af\u8fed\u4ee3\u53d8\u91cf\u662f per-variable-per-loop \u800c\u4e0d\u662f per-variable-per-iteration\u3002\u5982\u679c\u662f\u901a\u8fc7\u5c40\u90e8\u53d8\u91cf\uff08\u7528\u8fed\u4ee3\u53d8\u91cf\u6765\u521d\u59cb\u5316\uff09\u6216\u8005\u4f7f\u7528\u7d22\u5f15\u503c\u6765\u76f4\u63a5\u5f15\u7528\u8fed\u4ee3\u7684\u5143\u7d20\uff0c\u5c06\u6709\u52a9\u4e8e\u907f\u514d\u62f7\u8d1d\u6307\u9488(\u8fed\u4ee3\u53d8\u91cf\u7684\u5730\u5740)\u4e4b\u7c7b\u7684bug\u3002
\u4f7f\u7528map\u65f6\uff0c\u4e3a\u4e86\u80fd\u5f97\u5230\u786e\u5b9a\u4e00\u81f4\u7684\u7ed3\u679c\uff0c\u5e94\u8be5\u8bb0\u4f4fGo\u4e2d\u7684map\u6570\u636e\u7ed3\u6784\uff1a * \u4e0d\u4f1a\u6309\u7167key\u5bf9data\u8fdb\u884c\u6392\u5e8f\uff0c\u904d\u5386\u65f6\u4e0d\u662f\u6309key\u6709\u5e8f\u7684\uff1b * \u904d\u5386\u65f6\u7684\u987a\u5e8f\uff0c\u4e5f\u4e0d\u662f\u6309\u7167\u63d2\u5165\u65f6\u7684\u987a\u5e8f\uff1b * \u6ca1\u6709\u4e00\u4e2a\u786e\u5b9a\u6027\u7684\u904d\u5386\u987a\u5e8f\uff0c\u6bcf\u6b21\u904d\u5386\u987a\u5e8f\u662f\u4e0d\u540c\u7684\uff1b * \u4e0d\u80fd\u4fdd\u8bc1\u8fed\u4ee3\u8fc7\u7a0b\u4e2d\u65b0\u63d2\u5165\u7684\u5143\u7d20\uff0c\u5728\u5f53\u524d\u8fed\u4ee3\u4e2d\u80fd\u591f\u88ab\u904d\u5386\u5230\uff1b
"},{"location":"zh/#break-34","title":"\u5ffd\u7565\u4e86break
\u8bed\u53e5\u662f\u5982\u4f55\u5de5\u4f5c\u7684 (#34)","text":"\u914d\u5408label\u4f7f\u7528 break
\u548c continue
\uff0c\u80fd\u591f\u8df3\u8fc7\u4e00\u4e2a\u7279\u5b9a\u7684\u8bed\u53e5\uff0c\u5728\u67d0\u4e9b\u5faa\u73af\u4e2d\u5b58\u5728 switch
\u548cselect
\u8bed\u53e5\u7684\u573a\u666f\u4e2d\u5c31\u6bd4\u8f83\u6709\u5e2e\u52a9\u3002
defer
(#35)","text":"\u5728\u5faa\u73af\u4e2d\u4f7f\u7528defer\u4e0d\u80fd\u5728\u6bcf\u8f6e\u8fed\u4ee3\u7ed3\u675f\u65f6\u6267\u884cdefer\u8bed\u53e5\uff0c\u4f46\u662f\u5c06\u5faa\u73af\u903b\u8f91\u63d0\u53d6\u5230\u51fd\u6570\u5185\u90e8\u4f1a\u5728\u6bcf\u6b21\u8fed\u4ee3\u7ed3\u675f\u65f6\u6267\u884c defer \u8bed\u53e5\u3002
"},{"location":"zh/#_4","title":"\u5b57\u7b26\u4e32","text":""},{"location":"zh/#rune-36","title":"\u6ca1\u6709\u7406\u89e3rune (#36)","text":"\u7406\u89e3rune\u7c7b\u578b\u5bf9\u5e94\u7684\u662f\u4e00\u4e2aunicode\u7801\u70b9\uff0c\u6bcf\u4e00\u4e2aunicode\u7801\u70b9\u5176\u5b9e\u662f\u4e00\u4e2a\u591a\u5b57\u8282\u7684\u5e8f\u5217\uff0c\u4e0d\u662f\u4e00\u4e2abyte\u3002\u8fd9\u5e94\u8be5\u662fGo\u5f00\u53d1\u8005\u7684\u6838\u5fc3\u77e5\u8bc6\u70b9\u4e4b\u4e00\uff0c\u7406\u89e3\u4e86\u8fd9\u4e2a\u6709\u52a9\u4e8e\u66f4\u51c6\u786e\u5730\u5904\u7406\u5b57\u7b26\u4e32\u3002
"},{"location":"zh/#37","title":"\u4e0d\u6b63\u786e\u7684\u5b57\u7b26\u4e32\u904d\u5386 (#37)","text":"\u4f7f\u7528 range
\u64cd\u4f5c\u7b26\u5bf9\u4e00\u4e2astring\u8fdb\u884c\u904d\u5386\u5b9e\u9645\u4e0a\u662f\u5bf9string\u5bf9\u5e94\u7684 []rune
\u8fdb\u884c\u904d\u5386\uff0c\u8fed\u4ee3\u53d8\u91cf\u4e2d\u7684\u7d22\u5f15\u503c\uff0c\u8868\u793a\u7684\u5f53\u524drune\u5bf9\u5e94\u7684 []byte
\u5728\u6574\u4e2a []byte(string)
\u4e2d\u7684\u8d77\u59cb\u7d22\u5f15\u3002\u5982\u679c\u8981\u8bbf\u95eestring\u4e2d\u7684\u67d0\u4e00\u4e2arune\uff08\u6bd4\u5982\u7b2c\u4e09\u4e2a\uff09\uff0c\u9996\u5148\u8981\u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a []rune
\u7136\u540e\u518d\u6309\u7d22\u5f15\u503c\u8bbf\u95ee\u3002
strings.TrimRight
/strings.TrimLeft
\u79fb\u9664\u5728\u5b57\u7b26\u4e32\u5c3e\u90e8\u6216\u8005\u5f00\u5934\u51fa\u73b0\u7684\u4e00\u4e9brunes\uff0c\u51fd\u6570\u4f1a\u6307\u5b9a\u4e00\u4e2arune\u96c6\u5408\uff0c\u51fa\u73b0\u5728\u96c6\u5408\u4e2d\u7684rune\u5c06\u88ab\u4ece\u5b57\u7b26\u4e32\u79fb\u9664\u3002\u800c strings.TrimSuffix
/strings.TrimPrefix
\u662f\u79fb\u9664\u5b57\u7b26\u4e32\u7684\u4e00\u4e2a\u540e\u7f00/\u524d\u7f00\u3002
\u5bf9\u4e00\u4e2a\u5b57\u7b26\u4e32\u5217\u8868\u8fdb\u884c\u904d\u5386\u62fc\u63a5\u64cd\u4f5c\uff0c\u5e94\u8be5\u901a\u8fc7 strings.Builder
\u6765\u5b8c\u6210\uff0c\u4ee5\u907f\u514d\u6bcf\u6b21\u8fed\u4ee3\u62fc\u63a5\u65f6\u90fd\u5206\u914d\u4e00\u4e2a\u65b0\u7684string\u5bf9\u8c61\u51fa\u6765\u3002
bytes
\u5305\u63d0\u4f9b\u4e86\u4e00\u4e9b\u548c strings
\u5305\u76f8\u4f3c\u7684\u64cd\u4f5c\uff0c\u53ef\u4ee5\u5e2e\u52a9\u907f\u514d []byte/string \u4e4b\u95f4\u7684\u8f6c\u6362\u3002
\u4f7f\u7528\u4e00\u4e2a\u5b50\u5b57\u7b26\u4e32\u7684\u62f7\u8d1d\uff0c\u6709\u52a9\u4e8e\u907f\u514d\u5185\u5b58\u6cc4\u6f0f\uff0c\u56e0\u4e3a\u5bf9\u4e00\u4e2a\u5b57\u7b26\u4e32\u7684s[low:high]\u64cd\u4f5c\u8fd4\u56de\u7684\u5b50\u5b57\u7b26\u4e32\uff0c\u5176\u4f7f\u7528\u4e86\u548c\u539f\u5b57\u7b26\u4e32s\u76f8\u540c\u7684\u5e95\u5c42\u6570\u7ec4\u3002
"},{"location":"zh/#_5","title":"\u51fd\u6570\u548c\u65b9\u6cd5","text":""},{"location":"zh/#42","title":"\u4e0d\u77e5\u9053\u4f7f\u7528\u54ea\u79cd\u63a5\u6536\u5668\u7c7b\u578b (#42)","text":"\u5bf9\u4e8e\u63a5\u6536\u5668\u7c7b\u578b\u662f\u91c7\u7528value\u7c7b\u578b\u8fd8\u662fpointer\u7c7b\u578b\uff0c\u5e94\u8be5\u53d6\u51b3\u4e8e\u4e0b\u9762\u8fd9\u51e0\u79cd\u56e0\u7d20\uff0c\u6bd4\u5982\uff1a\u65b9\u6cd5\u5185\u662f\u5426\u4f1a\u5bf9\u5b83\u8fdb\u884c\u4fee\u6539\uff0c\u5b83\u662f\u5426\u5305\u542b\u4e86\u4e00\u4e2a\u4e0d\u80fd\u88ab\u62f7\u8d1d\u7684\u5b57\u6bb5\uff0c\u4ee5\u53ca\u5b83\u8868\u793a\u7684\u5bf9\u8c61\u6709\u591a\u5927\u3002\u5982\u679c\u6709\u7591\u95ee\uff0c\u63a5\u6536\u5668\u53ef\u4ee5\u8003\u8651\u4f7f\u7528pointer\u7c7b\u578b\u3002
"},{"location":"zh/#43","title":"\u4ece\u4e0d\u4f7f\u7528\u547d\u540d\u7684\u8fd4\u56de\u503c (#43)","text":"\u4f7f\u7528\u547d\u540d\u7684\u8fd4\u56de\u503c\uff0c\u662f\u4e00\u79cd\u6709\u6548\u6539\u5584\u51fd\u6570\u3001\u65b9\u6cd5\u53ef\u8bfb\u6027\u7684\u65b9\u6cd5\uff0c\u7279\u522b\u662f\u8fd4\u56de\u503c\u5217\u8868\u4e2d\u6709\u591a\u4e2a\u7c7b\u578b\u76f8\u540c\u7684\u53c2\u6570\u3002\u53e6\u5916\uff0c\u56e0\u4e3a\u8fd4\u56de\u503c\u5217\u8868\u4e2d\u7684\u53c2\u6570\u662f\u7ecf\u8fc7\u96f6\u503c\u521d\u59cb\u5316\u8fc7\u7684\uff0c\u67d0\u4e9b\u573a\u666f\u4e0b\u4e5f\u4f1a\u7b80\u5316\u51fd\u6570\u3001\u65b9\u6cd5\u7684\u5b9e\u73b0\u3002\u4f46\u662f\u9700\u8981\u6ce8\u610f\u5b83\u7684\u4e00\u4e9b\u6f5c\u5728\u526f\u4f5c\u7528\u3002
"},{"location":"zh/#44","title":"\u4f7f\u7528\u547d\u540d\u7684\u8fd4\u56de\u503c\u65f6\u9884\u671f\u5916\u7684\u526f\u4f5c\u7528 (#44)","text":"\u89c1 #43.
\u4f7f\u7528\u547d\u540d\u7684\u8fd4\u56de\u503c\uff0c\u56e0\u4e3a\u5b83\u5df2\u7ecf\u88ab\u521d\u59cb\u5316\u4e86\u96f6\u503c\uff0c\u9700\u8981\u6ce8\u610f\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\u5f02\u5e38\u8fd4\u56de\u65f6\u662f\u5426\u9700\u8981\u7ed9\u5b83\u8d4b\u4e88\u4e00\u4e2a\u4e0d\u540c\u7684\u503c\uff0c\u6bd4\u5982\u8fd4\u56de\u503c\u5217\u8868\u5b9a\u4e49\u4e86\u4e00\u4e2a\u6709\u540d\u53c2\u6570 err error
\uff0c\u9700\u8981\u6ce8\u610f return err
\u65f6\u662f\u5426\u6b63\u786e\u5730\u5bf9 err
\u8fdb\u884c\u4e86\u8d4b\u503c\u3002
\u5f53\u8fd4\u56de\u4e00\u4e2ainterface\u53c2\u6570\u65f6\uff0c\u9700\u8981\u5c0f\u5fc3\uff0c\u4e0d\u8981\u8fd4\u56de\u4e00\u4e2anil\u6307\u9488\uff0c\u800c\u662f\u5e94\u8be5\u663e\u793a\u8fd4\u56de\u4e00\u4e2anil\u503c\u3002\u5426\u5219\uff0c\u53ef\u80fd\u4f1a\u53d1\u751f\u4e00\u4e9b\u9884\u671f\u5916\u7684\u95ee\u9898\uff0c\u56e0\u4e3a\u8c03\u7528\u65b9\u4f1a\u6536\u5230\u4e00\u4e2a\u975enil\u7684\u503c\u3002
"},{"location":"zh/#46","title":"\u4f7f\u7528\u6587\u4ef6\u540d\u4f5c\u4e3a\u51fd\u6570\u5165\u53c2 (#46)","text":"\u8bbe\u8ba1\u51fd\u6570\u65f6\u4f7f\u7528 io.Reader
\u7c7b\u578b\u4f5c\u4e3a\u5165\u53c2\uff0c\u800c\u4e0d\u662f\u6587\u4ef6\u540d\uff0c\u5c06\u6709\u52a9\u4e8e\u6539\u5584\u51fd\u6570\u7684\u53ef\u590d\u7528\u6027\u3001\u6613\u6d4b\u8bd5\u6027\u3002
defer
\u8bed\u53e5\u4e2d\u53c2\u6570\u3001\u63a5\u6536\u5668\u503c\u7684\u8ba1\u7b97\u65b9\u5f0f (\u53c2\u6570\u503c\u8ba1\u7b97, \u6307\u9488, \u548c value\u7c7b\u578b\u63a5\u6536\u5668) (#47)","text":"\u4e3a\u4e86\u907f\u514d defer
\u8bed\u53e5\u6267\u884c\u65f6\u5c31\u7acb\u5373\u8ba1\u7b97\u5bf9defer\u8981\u6267\u884c\u7684\u51fd\u6570\u7684\u53c2\u6570\u8fdb\u884c\u8ba1\u7b97\uff0c\u53ef\u4ee5\u8003\u8651\u5c06\u8981\u6267\u884c\u7684\u51fd\u6570\u653e\u5230\u95ed\u5305\u91cc\u9762\uff0c\u7136\u540e\u901a\u8fc7\u6307\u9488\u4f20\u9012\u53c2\u6570\u7ed9\u95ed\u5305\u5185\u51fd\u6570\uff08\u6216\u8005\u901a\u8fc7\u95ed\u5305\u6355\u83b7\u5916\u90e8\u53d8\u91cf\uff09\uff0c\u6765\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u3002
\u4f7f\u7528 panic
\u662fGo\u4e2d\u4e00\u79cd\u5904\u7406\u9519\u8bef\u7684\u65b9\u5f0f\uff0c\u4f46\u662f\u53ea\u80fd\u5728\u9047\u5230\u4e0d\u53ef\u6062\u590d\u7684\u9519\u8bef\u65f6\u4f7f\u7528\uff0c\u4f8b\u5982\uff1a\u901a\u77e5\u5f00\u53d1\u4eba\u5458\u4e00\u4e2a\u5f3a\u4f9d\u8d56\u7684\u6a21\u5757\u52a0\u8f7d\u5931\u8d25\u4e86\u3002
Wrapping\uff08\u5305\u88c5\uff09\u9519\u8bef\u5141\u8bb8\u60a8\u6807\u8bb0\u9519\u8bef\u3001\u63d0\u4f9b\u989d\u5916\u7684\u4e0a\u4e0b\u6587\u4fe1\u606f\u3002\u7136\u800c\uff0c\u5305\u88c5\u9519\u8bef\u4f1a\u521b\u5efa\u6f5c\u5728\u7684\u8026\u5408\uff0c\u56e0\u4e3a\u5b83\u4f7f\u5f97\u539f\u6765\u7684\u9519\u8bef\u5bf9\u8c03\u7528\u8005\u53ef\u89c1\u3002\u5982\u679c\u60a8\u60f3\u8981\u9632\u6b62\u8fd9\u79cd\u60c5\u51b5\uff0c\u8bf7\u4e0d\u8981\u4f7f\u7528\u5305\u88c5\u9519\u8bef\u7684\u65b9\u5f0f\u3002
"},{"location":"zh/#50","title":"\u4e0d\u6b63\u786e\u7684\u9519\u8bef\u7c7b\u578b\u6bd4\u8f83 (#50)","text":"\u5982\u679c\u4f60\u4f7f\u7528 Go 1.13 \u5f15\u5165\u7684\u7279\u6027 fmt.Errorf
+ %w
\u6765\u5305\u88c5\u4e00\u4e2a\u9519\u8bef\uff0c\u5f53\u8fdb\u884c\u9519\u8bef\u6bd4\u8f83\u65f6\uff0c\u5982\u679c\u60f3\u5224\u65ad\u8be5\u5305\u88c5\u540e\u7684\u9519\u8bef\u662f\u4e0d\u662f\u6307\u5b9a\u7684\u9519\u8bef\u7c7b\u578b\uff0c\u5c31\u9700\u8981\u4f7f\u7528 errors.As
\uff0c\u5982\u679c\u60f3\u5224\u65ad\u662f\u4e0d\u662f\u6307\u5b9a\u7684error\u5bf9\u8c61\u5c31\u9700\u8981\u7528 errors.Is
\u3002
\u89c1 #50.
\u4e3a\u4e86\u8868\u8fbe\u4e00\u4e2a\u9884\u671f\u5185\u7684\u9519\u8bef\uff0c\u8bf7\u4f7f\u7528\u9519\u8bef\u503c\u7684\u65b9\u5f0f\uff0c\u5e76\u901a\u8fc7 ==
\u6216\u8005 errors.Is
\u6765\u6bd4\u8f83\u3002\u800c\u5bf9\u4e8e\u610f\u5916\u9519\u8bef\uff0c\u5219\u5e94\u4f7f\u7528\u7279\u5b9a\u7684\u9519\u8bef\u7c7b\u578b\uff08\u53ef\u4ee5\u901a\u8fc7 errors.As
\u6765\u6bd4\u8f83\uff09\u3002
\u5927\u591a\u6570\u60c5\u51b5\u4e0b\uff0c\u9519\u8bef\u4ec5\u9700\u8981\u5904\u7406\u4e00\u6b21\u3002\u6253\u5370\u9519\u8bef\u65e5\u5fd7\u4e5f\u662f\u4e00\u79cd\u9519\u8bef\u5904\u7406\u3002\u56e0\u6b64\uff0c\u5f53\u51fd\u6570\u5185\u53d1\u751f\u9519\u8bef\u65f6\uff0c\u5e94\u8be5\u5728\u6253\u5370\u65e5\u5fd7\u548c\u8fd4\u56de\u9519\u8bef\u4e2d\u9009\u62e9\u5176\u4e2d\u4e00\u79cd\u3002\u5305\u88c5\u9519\u8bef\u4e5f\u53ef\u4ee5\u63d0\u4f9b\u95ee\u9898\u53d1\u751f\u7684\u989d\u5916\u4e0a\u4e0b\u6587\u4fe1\u606f\uff0c\u4e5f\u5305\u62ec\u4e86\u539f\u6765\u7684\u9519\u8bef\uff08\u53ef\u8003\u8651\u4ea4\u7ed9\u8c03\u7528\u65b9\u8d1f\u8d23\u6253\u65e5\u5fd7\uff09\u3002
"},{"location":"zh/#53","title":"\u4e0d\u5904\u7406\u9519\u8bef (#53)","text":"\u4e0d\u7ba1\u662f\u5728\u51fd\u6570\u8c03\u7528\u65f6\uff0c\u8fd8\u662f\u5728\u4e00\u4e2a defer
\u51fd\u6570\u6267\u884c\u65f6\uff0c\u5982\u679c\u60f3\u8981\u5ffd\u7565\u4e00\u4e2a\u9519\u8bef\uff0c\u5e94\u8be5\u663e\u793a\u5730\u901a\u8fc7 _
\u6765\u5ffd\u7565\uff08\u53ef\u6ce8\u660e\u5ffd\u7565\u7684\u539f\u56e0\uff09\u3002\u5426\u5219\uff0c\u5c06\u6765\u7684\u8bfb\u8005\u5c31\u4f1a\u611f\u89c9\u5230\u56f0\u60d1\uff0c\u5ffd\u7565\u8fd9\u4e2a\u9519\u8bef\u662f\u6709\u610f\u4e3a\u4e4b\u8fd8\u662f\u65e0\u610f\u4e2d\u6f0f\u6389\u4e86\u3002
defer
\u4e2d\u7684\u9519\u8bef (#54)","text":"\u5927\u591a\u6570\u60c5\u51b5\u4e0b\uff0c\u4f60\u4e0d\u5e94\u8be5\u5ffd\u7565 defer
\u51fd\u6570\u6267\u884c\u65f6\u8fd4\u56de\u7684\u9519\u8bef\uff0c\u6216\u8005\u663e\u793a\u5904\u7406\u5b83\uff0c\u6216\u8005\u5c06\u5b83\u4f20\u9012\u7ed9\u8c03\u7528\u65b9\u5904\u7406\uff0c\u53ef\u4ee5\u6839\u636e\u60c5\u666f\u8fdb\u884c\u9009\u62e9\u3002\u5982\u679c\u4f60\u786e\u5b9a\u8981\u5ffd\u7565\u8fd9\u4e2a\u9519\u8bef\uff0c\u8bf7\u663e\u793a\u4f7f\u7528 _
\u6765\u5ffd\u7565\u3002
\u7406\u89e3\u5e76\u53d1\uff08concurrency\uff09\u3001\u5e76\u884c\uff08parallelism\uff09\u4e4b\u95f4\u7684\u672c\u8d28\u533a\u522b\u662fGo\u5f00\u53d1\u4eba\u5458\u5fc5\u987b\u8981\u638c\u63e1\u7684\u3002\u5e76\u53d1\u662f\u5173\u4e8e\u7ed3\u6784\u8bbe\u8ba1\u4e0a\u7684\uff0c\u5e76\u884c\u662f\u5173\u4e8e\u5177\u4f53\u6267\u884c\u4e0a\u7684\u3002
"},{"location":"zh/#56","title":"\u8ba4\u4e3a\u5e76\u53d1\u603b\u662f\u66f4\u5feb (#56)","text":"\u8981\u6210\u4e3a\u4e00\u540d\u719f\u7ec3\u7684\u5f00\u53d1\u4eba\u5458\uff0c\u60a8\u5fc5\u987b\u610f\u8bc6\u5230\u5e76\u975e\u6240\u6709\u573a\u666f\u4e0b\u90fd\u662f\u5e76\u53d1\u7684\u65b9\u6848\u66f4\u5feb\u3002\u5bf9\u4e8e\u4efb\u52a1\u4e2d\u7684\u6700\u5c0f\u5de5\u4f5c\u8d1f\u8f7d\u90e8\u5206\uff0c\u5bf9\u5b83\u4eec\u8fdb\u884c\u5e76\u884c\u5316\u5904\u7406\u5e76\u4e0d\u4e00\u5b9a\u5c31\u6709\u660e\u663e\u6536\u76ca\u6216\u8005\u6bd4\u4e32\u884c\u5316\u65b9\u6848\u66f4\u5feb\u3002\u5bf9\u4e32\u884c\u5316\u3001\u5e76\u53d1\u65b9\u6848\u8fdb\u884cbenchmark\u6d4b\u8bd5\uff0c\u662f\u9a8c\u8bc1\u5047\u8bbe\u7684\u597d\u529e\u6cd5\u3002
"},{"location":"zh/#channelsmutexes-57","title":"\u4e0d\u6e05\u695a\u4f55\u65f6\u4f7f\u7528channels\u6216mutexes (#57)","text":"\u4e86\u89e3 goroutine \u4e4b\u95f4\u7684\u4ea4\u4e92\u4e5f\u53ef\u4ee5\u5728\u9009\u62e9\u4f7f\u7528channels\u6216mutexes\u65f6\u6709\u6240\u5e2e\u52a9\u3002\u4e00\u822c\u6765\u8bf4\uff0c\u5e76\u884c\u7684 goroutine \u9700\u8981\u540c\u6b65\uff0c\u56e0\u6b64\u9700\u8981\u4f7f\u7528mutexes\u3002\u76f8\u53cd\uff0c\u5e76\u53d1\u7684 goroutine \u901a\u5e38\u9700\u8981\u534f\u8c03\u548c\u7f16\u6392\uff0c\u56e0\u6b64\u9700\u8981\u4f7f\u7528channels\u3002
"},{"location":"zh/#vs-go-58","title":"\u4e0d\u660e\u767d\u7ade\u6001\u95ee\u9898 (\u6570\u636e\u7ade\u6001 vs. \u7ade\u6001\u6761\u4ef6 \u548c Go\u5185\u5b58\u6a21\u578b) (#58)","text":"\u638c\u63e1\u5e76\u53d1\u610f\u5473\u7740\u8981\u8ba4\u8bc6\u5230\u6570\u636e\u7ade\u4e89\uff08data races\uff09\u548c\u7ade\u6001\u6761\u4ef6\uff08race conditions\uff09\u662f\u4e24\u4e2a\u4e0d\u540c\u7684\u6982\u5ff5\u3002\u6570\u636e\u7ade\u4e89\uff0c\u6307\u7684\u662f\u6709\u591a\u4e2agoroutines\u540c\u65f6\u8bbf\u95ee\u76f8\u540c\u5185\u5b58\u533a\u57df\u65f6\uff0c\u6ca1\u6709\u5fc5\u8981\u7684\u540c\u6b65\u63a7\u5236\uff0c\u4e14\u5176\u4e2d\u81f3\u5c11\u6709\u4e00\u4e2agoroutine\u662f\u6267\u884c\u7684\u5199\u64cd\u4f5c\u3002\u540c\u65f6\u8981\u8ba4\u8bc6\u5230\uff0c\u6ca1\u6709\u53d1\u751f\u6570\u636e\u7ade\u4e89\u4e0d\u4ee3\u8868\u7a0b\u5e8f\u7684\u6267\u884c\u662f\u786e\u5b9a\u6027\u7684\u3001\u6ca1\u95ee\u9898\u7684\u3002\u5f53\u5728\u67d0\u4e2a\u7279\u5b9a\u7684\u64cd\u4f5c\u987a\u5e8f\u6216\u8005\u7279\u5b9a\u7684\u4e8b\u4ef6\u53d1\u751f\u987a\u5e8f\u4e0b\uff0c\u5982\u679c\u6700\u7ec8\u7684\u884c\u4e3a\u662f\u4e0d\u53ef\u63a7\u7684\uff0c\u8fd9\u5c31\u662f\u7ade\u6001\u6761\u4ef6\u3002
ps\uff1a\u6570\u636e\u7ade\u4e89\u662f\u7ade\u6001\u6761\u4ef6\u7684\u5b50\u96c6\uff0c\u7ade\u6001\u6761\u4ef6\u4e0d\u4ec5\u5c40\u9650\u4e8e\u8bbf\u5b58\u672a\u540c\u6b65\uff0c\u5b83\u53ef\u4ee5\u53d1\u751f\u5728\u66f4\u9ad8\u7684\u5c42\u9762\u3002go test -race
\u68c0\u6d4b\u7684\u662f\u6570\u636e\u7ade\u4e89\uff0c\u9700\u8981\u540c\u6b65\u6765\u89e3\u51b3\uff0c\u800c\u5f00\u53d1\u8005\u8fd8\u9700\u8981\u5173\u6ce8\u9762\u66f4\u5e7f\u7684\u7ade\u6001\u6761\u4ef6\uff0c\u5b83\u9700\u8981\u5bf9\u591a\u4e2agoroutines\u7684\u6267\u884c\u8fdb\u884c\u7f16\u6392\u3002
\u7406\u89e3 Go \u7684\u5185\u5b58\u6a21\u578b\u4ee5\u53ca\u6709\u5173\u987a\u5e8f\u548c\u540c\u6b65\u7684\u5e95\u5c42\u4fdd\u8bc1\u662f\u9632\u6b62\u53ef\u80fd\u7684\u6570\u636e\u7ade\u4e89\u548c\u7ade\u6001\u6761\u4ef6\u7684\u5173\u952e\u3002
"},{"location":"zh/#59","title":"\u4e0d\u7406\u89e3\u4e0d\u540c\u5de5\u4f5c\u8d1f\u8f7d\u7c7b\u578b\u5bf9\u5e76\u53d1\u7684\u5f71\u54cd (#59)","text":"\u5f53\u521b\u5efa\u4e00\u5b9a\u6570\u91cf\u7684goroutines\u662f\uff0c\u9700\u8981\u8003\u8651\u5de5\u4f5c\u8d1f\u8f7d\u7684\u7c7b\u578b\u3002\u5982\u679c\u5de5\u4f5c\u8d1f\u8f7d\u662fCPU\u5bc6\u96c6\u578b\u7684\uff0c\u90a3\u4e48goroutines\u6570\u91cf\u5e94\u8be5\u63a5\u8fd1\u4e8e GOMAXPROCS
\u7684\u503c\uff08\u8be5\u503c\u53d6\u51b3\u4e8e\u4e3b\u673a\u5904\u7406\u5668\u6838\u5fc3\u6570\uff09\u3002\u5982\u679c\u5de5\u4f5c\u8d1f\u8f7d\u662fIO\u5bc6\u96c6\u578b\u7684\uff0cgoroutines\u6570\u91cf\u5c31\u9700\u8981\u8003\u8651\u591a\u79cd\u56e0\u7d20\uff0c\u6bd4\u5982\u5916\u90e8\u7cfb\u7edf\uff08\u8003\u8651\u8bf7\u6c42\u3001\u54cd\u5e94\u901f\u7387\uff09\u3002
Go \u7684\u4e0a\u4e0b\u6587\uff08context\uff09\u4e5f\u662f Go \u5e76\u53d1\u7f16\u7a0b\u7684\u57fa\u77f3\u4e4b\u4e00\u3002\u4e0a\u4e0b\u6587\u5141\u8bb8\u60a8\u643a\u5e26\u622a\u6b62\u65f6\u95f4\u3001\u53d6\u6d88\u4fe1\u53f7\u548c\u952e\u503c\u5217\u8868\u3002
"},{"location":"zh/#_8","title":"\u5e76\u53d1\u7f16\u7a0b: \u5b9e\u8df5","text":""},{"location":"zh/#context-61","title":"\u4f20\u9012\u4e0d\u5408\u9002\u7684context (#61)","text":"\u5f53\u6211\u4eec\u4f20\u9012\u4e86\u4e00\u4e2acontext\uff0c\u6211\u4eec\u9700\u8981\u77e5\u9053\u8fd9\u4e2acontext\u4ec0\u4e48\u65f6\u5019\u53ef\u4ee5\u88ab\u53d6\u6d88\uff0c\u8fd9\u70b9\u5f88\u91cd\u8981\uff0c\u4f8b\u5982\uff1a\u4e00\u4e2aHTTP\u8bf7\u6c42\u5904\u7406\u5668\u5728\u53d1\u9001\u5b8c\u54cd\u5e94\u540e\u53d6\u6d88context\u3002
ps: \u5b9e\u9645\u4e0acontext\u8868\u8fbe\u7684\u662f\u4e00\u4e2a\u52a8\u4f5c\u53ef\u4ee5\u6301\u7eed\u591a\u4e45\u4e4b\u540e\u88ab\u505c\u6b62\u3002
"},{"location":"zh/#goroutine-62","title":"\u542f\u52a8\u4e86\u4e00\u4e2agoroutine\u4f46\u662f\u4e0d\u77e5\u9053\u5b83\u4f55\u65f6\u4f1a\u505c\u6b62 (#62)","text":"\u907f\u514dgoroutine\u6cc4\u6f0f\uff0c\u8981\u6709\u8fd9\u79cd\u610f\u8bc6\uff0c\u5f53\u521b\u5efa\u5e76\u542f\u52a8\u4e00\u4e2agoroutine\u7684\u65f6\u5019\uff0c\u5e94\u8be5\u6709\u5bf9\u5e94\u7684\u8bbe\u8ba1\u8ba9\u5b83\u80fd\u6b63\u5e38\u9000\u51fa\u3002
"},{"location":"zh/#goroutines-63","title":"\u4e0d\u6ce8\u610f\u5904\u7406 goroutines \u548c \u5faa\u73af\u4e2d\u7684\u8fed\u4ee3\u53d8\u91cf (#63)","text":"\u4e3a\u4e86\u907f\u514dgoroutines\u548c\u5faa\u73af\u4e2d\u7684\u8fed\u4ee3\u53d8\u91cf\u95ee\u9898\uff0c\u53ef\u4ee5\u8003\u8651\u521b\u5efa\u5c40\u90e8\u53d8\u91cf\u5e76\u5c06\u8fed\u4ee3\u53d8\u91cf\u8d4b\u503c\u7ed9\u5c40\u90e8\u53d8\u91cf\uff0c\u6216\u8005goroutine\u8c03\u7528\u5e26\u53c2\u6570\u7684\u51fd\u6570\uff0c\u5c06\u8fed\u4ee3\u53d8\u91cf\u503c\u4f5c\u4e3a\u53c2\u6570\u503c\u4f20\u5165\uff0c\u6765\u4ee3\u66ffgoroutine\u8c03\u7528\u95ed\u5305\u3002
"},{"location":"zh/#select-channels-64","title":"\u4f7f\u7528select + channels \u65f6\u8bef\u4ee5\u4e3a\u5206\u652f\u9009\u62e9\u987a\u5e8f\u662f\u786e\u5b9a\u7684 (#64)","text":"\u8981\u660e\u767d\uff0cselect
\u591a\u4e2achannels\u65f6\uff0c\u5982\u679c\u591a\u4e2achannels\u4e0a\u7684\u64cd\u4f5c\u90fd\u5c31\u7eea\uff0c\u90a3\u4e48\u4f1a\u968f\u673a\u9009\u62e9\u4e00\u4e2a case
\u5206\u652f\u6765\u6267\u884c\uff0c\u56e0\u6b64\u8981\u907f\u514d\u6709\u5206\u652f\u9009\u62e9\u987a\u5e8f\u662f\u4ece\u4e0a\u5230\u4e0b\u7684\u8fd9\u79cd\u9519\u8bef\u9884\u8bbe\uff0c\u8fd9\u53ef\u80fd\u4f1a\u5bfc\u81f4\u8bbe\u8ba1\u4e0a\u7684bug\u3002
\u53d1\u9001\u901a\u77e5\u65f6\u4f7f\u7528 chan struct{}
\u7c7b\u578b\u3002
ps: \u5148\u660e\u767d\u4ec0\u4e48\u662f\u901a\u77e5channels\uff0c\u4e00\u4e2a\u901a\u77e5channels\u6307\u7684\u662f\u53ea\u662f\u7528\u6765\u505a\u901a\u77e5\uff0c\u800c\u5176\u4e2d\u4f20\u9012\u7684\u6570\u636e\u6ca1\u6709\u610f\u4e49\uff0c\u6216\u8005\u7406\u89e3\u6210\u4e0d\u4f20\u9012\u6570\u636e\u7684channels\uff0c\u8fd9\u79cd\u79f0\u4e3a\u901a\u77e5channels\u3002\u5176\u4e2d\u4f20\u9012\u7684\u6570\u636e\u7684\u7c7b\u578bstruct{}\u66f4\u5408\u9002\u3002
"},{"location":"zh/#nil-channels-66","title":"\u4e0d\u4f7f\u7528 nil channels (#66)","text":"\u4f7f\u7528 nil channels \u5e94\u8be5\u662f\u5e76\u53d1\u5904\u7406\u65b9\u5f0f\u4e2d\u7684\u4e00\u90e8\u5206\uff0c\u4f8b\u5982\uff0c\u5b83\u80fd\u591f\u5e2e\u52a9\u7981\u7528 select
\u8bed\u53e5\u4e2d\u7684\u7279\u5b9a\u7684\u5206\u652f\u3002
\u6839\u636e\u6307\u5b9a\u7684\u573a\u666f\u4ed4\u7ec6\u8bc4\u4f30\u5e94\u8be5\u4f7f\u7528\u54ea\u4e00\u79cd channel \u7c7b\u578b\uff08\u5e26\u7f13\u51b2\u7684\uff0c\u4e0d\u5e26\u7f13\u51b2\u7684\uff09\u3002\u53ea\u6709\u4e0d\u5e26\u7f13\u51b2\u7684 channels \u53ef\u4ee5\u63d0\u4f9b\u5f3a\u540c\u6b65\u4fdd\u8bc1\u3002
\u4f7f\u7528\u5e26\u7f13\u51b2\u7684 channels \u65f6\u5982\u679c\u4e0d\u786e\u5b9a size \u8be5\u5982\u4f55\u8bbe\u7f6e\uff0c\u53ef\u4ee5\u5148\u8bbe\u4e3a1\uff0c\u5982\u679c\u6709\u5408\u7406\u7684\u7406\u7531\u518d\u53bb\u6307\u5b9a channels size\u3002
ps: \u6839\u636edisruptor\u8fd9\u4e2a\u9ad8\u6027\u80fd\u5185\u5b58\u6d88\u606f\u961f\u5217\u7684\u5b9e\u8df5\uff0c\u5728\u67d0\u79cd\u8bfb\u5199pacing\u4e0b\uff0c\u961f\u5217\u8981\u4e48\u6ee1\u8981\u4e48\u7a7a\uff0c\u4e0d\u5927\u53ef\u80fd\u5904\u4e8e\u67d0\u79cd\u4ecb\u4e8e\u4e2d\u95f4\u7684\u7a33\u6001\u3002
"},{"location":"zh/#etcd-68","title":"\u5fd8\u8bb0\u4e86\u5b57\u7b26\u4e32\u683c\u5f0f\u5316\u53ef\u80fd\u5e26\u6765\u7684\u526f\u4f5c\u7528\uff08\u4f8b\u5982 etcd \u6570\u636e\u7ade\u4e89\u548c\u6b7b\u9501\uff09(#68)","text":"\u610f\u8bc6\u5230\u5b57\u7b26\u4e32\u683c\u5f0f\u5316\u53ef\u80fd\u4f1a\u5bfc\u81f4\u8c03\u7528\u73b0\u6709\u51fd\u6570\uff0c\u8fd9\u610f\u5473\u7740\u9700\u8981\u6ce8\u610f\u53ef\u80fd\u7684\u6b7b\u9501\u548c\u5176\u4ed6\u6570\u636e\u7ade\u4e89\u95ee\u9898\u3002
ps: \u6838\u5fc3\u662f\u8981\u5173\u6ce8 fmt.Sprintf
+ %v
\u8fdb\u884c\u5b57\u7b26\u4e32\u683c\u5f0f\u5316\u65f6 %v
\u5177\u4f53\u5230\u4e0d\u540c\u7684\u7c7b\u578b\u503c\u65f6\uff0c\u5b9e\u9645\u4e0a\u6267\u884c\u7684\u64cd\u4f5c\u662f\u4ec0\u4e48\u3002\u6bd4\u5982 %v
\u8fd9\u4e2aplaceholder\u5bf9\u5e94\u7684\u503c\u65f6\u4e00\u4e2a context.Context
\uff0c\u90a3\u4e48\u4f1a\u5c31\u904d\u5386\u5176\u901a\u8fc7 context.WithValue
\u9644\u52a0\u5728\u5176\u4e2d\u7684 values\uff0c\u8fd9\u4e2a\u8fc7\u7a0b\u53ef\u80fd\u6d89\u53ca\u5230\u6570\u636e\u7ade\u4e89\u95ee\u9898\u3002\u4e66\u4e2d\u63d0\u53ca\u7684\u53e6\u4e00\u4e2a\u5bfc\u81f4\u6b7b\u9501\u7684\u6848\u4f8b\u672c\u8d28\u4e0a\u4e5f\u662f\u4e00\u6837\u7684\u95ee\u9898\uff0c\u53ea\u4e0d\u8fc7\u53c8\u989d\u5916\u7275\u626f\u5230\u4e86 sync.RWMutex
\u4e0d\u53ef\u91cd\u5165\u7684\u95ee\u9898\u3002
\u8c03\u7528 append
\u4e0d\u603b\u662f\u6ca1\u6709\u6570\u636e\u7ade\u4e89\u7684\uff0c\u56e0\u6b64\u4e0d\u8981\u5728\u4e00\u4e2a\u5171\u4eab\u7684 slice
\u4e0a\u5e76\u53d1\u5730\u6267\u884c append
\u3002
\u8bf7\u8bb0\u4f4f slices \u548c maps \u5f15\u7528\u7c7b\u578b\uff0c\u6709\u52a9\u4e8e\u907f\u514d\u5e38\u89c1\u7684\u6570\u636e\u7ade\u4e89\u95ee\u9898\u3002
ps: \u8fd9\u91cc\u5b9e\u9645\u662f\u56e0\u4e3a\u9519\u8bef\u7406\u89e3\u4e86 slices \u548c maps\uff0c\u5bfc\u81f4\u5199\u51fa\u4e86\u9519\u8bef\u7684\u62f7\u8d1d slices \u548c maps \u7684\u4ee3\u7801\uff0c\u8fdb\u800c\u5bfc\u81f4\u9501\u4fdd\u62a4\u65e0\u6548\u3001\u51fa\u73b0\u6570\u636e\u7ade\u4e89\u95ee\u9898\u3002
"},{"location":"zh/#syncwaitgroup-71","title":"\u8bef\u7528sync.WaitGroup
(#71)","text":"\u6b63\u786e\u5730\u4f7f\u7528 sync.WaitGroup
\u9700\u8981\u5728\u542f\u52a8 goroutines \u4e4b\u524d\u5148\u8c03\u7528 Add
\u65b9\u6cd5\u3002
sync.Cond
(#72)","text":"\u4f60\u53ef\u4ee5\u4f7f\u7528 sync.Cond
\u5411\u591a\u4e2a goroutines \u53d1\u9001\u91cd\u590d\u7684\u901a\u77e5\u3002
errgroup
(#73)","text":"\u4f60\u53ef\u4ee5\u4f7f\u7528 errgroup
\u5305\u6765\u540c\u6b65\u4e00\u7ec4 goroutines \u5e76\u5904\u7406\u9519\u8bef\u548c\u4e0a\u4e0b\u6587\u3002
sync
\u4e0b\u7684\u7c7b\u578b (#74)","text":"sync
\u5305\u4e0b\u7684\u7c7b\u578b\u4e0d\u5e94\u8be5\u88ab\u62f7\u8d1d\u3002
\u6ce8\u610f\u6709\u4e9b\u51fd\u6570\u63a5\u6536\u4e00\u4e2a time.Duration
\u7c7b\u578b\u7684\u53c2\u6570\u65f6\uff0c\u5c3d\u7ba1\u76f4\u63a5\u4f20\u9012\u4e00\u4e2a\u6574\u6570\u662f\u53ef\u4ee5\u7684\uff0c\u4f46\u6700\u597d\u8fd8\u662f\u4f7f\u7528 time API \u4e2d\u7684\u65b9\u6cd5\u6765\u4f20\u9012 duration\uff0c\u4ee5\u907f\u514d\u53ef\u80fd\u9020\u6210\u7684\u56f0\u60d1\u3001bug\u3002
ps: \u91cd\u70b9\u662f\u6ce8\u610f time.Duration \u5b9a\u4e49\u7684\u662f nanoseconds \u6570\u3002
"},{"location":"zh/#timeafter-76","title":"time.After
\u548c\u5185\u5b58\u6cc4\u6f0f (#76)","text":"\u907f\u514d\u5728\u91cd\u590d\u6267\u884c\u5f88\u591a\u6b21\u7684\u51fd\u6570 \uff08\u5982\u5faa\u73af\u4e2d\u6216HTTP\u5904\u7406\u51fd\u6570\uff09\u4e2d\u8c03\u7528 time.After
\uff0c\u8fd9\u53ef\u4ee5\u907f\u514d\u5185\u5b58\u5cf0\u503c\u6d88\u8017\u3002\u7531 time.After
\u521b\u5efa\u7684\u8d44\u6e90\u4ec5\u5728\u8ba1\u65f6\u5668\u8d85\u65f6\u624d\u4f1a\u88ab\u91ca\u653e\u3002
\u8981\u5f53\u5fc3\u5728Go\u7ed3\u6784\u4f53\u4e2d\u5d4c\u5165\u5b57\u6bb5\uff0c\u8fd9\u6837\u505a\u53ef\u80fd\u4f1a\u5bfc\u81f4\u8bf8\u5982\u5d4c\u5165\u7684 time.Time
\u5b57\u6bb5\u5b9e\u73b0 json.Marshaler
\u63a5\u53e3\uff0c\u4ece\u800c\u8986\u76d6\u9ed8\u8ba4\u7684json\u5e8f\u5217\u3002
\u5f53\u5bf9\u4e24\u4e2a time.Time
\u7c7b\u578b\u503c\u8fdb\u884c\u6bd4\u8f83\u65f6\uff0c\u9700\u8981\u8bb0\u4f4f time.Time
\u5305\u542b\u4e86\u4e00\u4e2a\u5899\u4e0a\u65f6\u949f\uff08wall clock\uff09\u548c\u4e00\u4e2a\u5355\u8c03\u65f6\u949f \uff08monotonic clock\uff09\uff0c\u800c\u4f7f\u7528 ==
\u8fd0\u7b97\u7b26\u8fdb\u884c\u6bd4\u8f83\u65f6\u4f1a\u540c\u65f6\u6bd4\u8f83\u8fd9\u4e24\u4e2a\u3002
any
\u5f53\u63d0\u4f9b\u4e00\u4e2amap\u7528\u6765unmarshal JSON\u6570\u636e\u65f6\uff0c\u4e3a\u4e86\u907f\u514d\u4e0d\u786e\u5b9a\u7684value\u7ed3\u6784\u6211\u4eec\u4f1a\u4f7f\u7528 any
\u6765\u4f5c\u4e3avalue\u7684\u7c7b\u578b\u800c\u4e0d\u662f\u5b9a\u4e49\u4e00\u4e2astruct\uff0c\u8fd9\u79cd\u60c5\u51b5\u4e0b\u9700\u8981\u8bb0\u5f97\u6570\u503c\u9ed8\u8ba4\u4f1a\u88ab\u8f6c\u6362\u4e3a float64
\u3002
sql.Open
\u5e76\u6ca1\u6709\u4e0edb\u670d\u52a1\u5668\u5efa\u7acb\u5b9e\u9645\u8fde\u63a5\u9700\u8981\u8c03\u7528 Ping
\u6216\u8005 PingContext
\u65b9\u6cd5\u6765\u6d4b\u8bd5\u914d\u7f6e\u5e76\u786e\u4fdd\u6570\u636e\u5e93\u662f\u53ef\u8fbe\u7684\u3002
\u4f5c\u4e3a\u751f\u4ea7\u7ea7\u522b\u7684\u5e94\u7528\uff0c\u8bbf\u95ee\u6570\u636e\u5e93\u65f6\u5e94\u8be5\u5173\u6ce8\u914d\u7f6e\u6570\u636e\u5e93\u8fde\u63a5\u6c60\u53c2\u6570\u3002
\u4f7f\u7528 SQL prepared \u8bed\u53e5\u80fd\u591f\u8ba9\u67e5\u8be2\u66f4\u52a0\u9ad8\u6548\u548c\u5b89\u5168\u3002
\u4f7f\u7528 sql.NullXXX
\u7c7b\u578b\u5904\u7406\u8868\u4e2d\u7684\u53ef\u7a7a\u5217\u3002
\u8c03\u7528 sql.Rows
\u7684 Err
\u65b9\u6cd5\u6765\u786e\u4fdd\u5728\u51c6\u5907\u4e0b\u4e00\u4e2a\u884c\u65f6\u6ca1\u6709\u9057\u6f0f\u9519\u8bef\u3002
sql.Rows
\u548c os.File
) (#79)","text":"\u6700\u7ec8\u8981\u6ce8\u610f\u5173\u95ed\u6240\u6709\u5b9e\u73b0 io.Closer
\u63a5\u53e3\u7684\u7ed3\u6784\u4f53,\u4ee5\u907f\u514d\u53ef\u80fd\u7684\u6cc4\u6f0f\u3002
\u4e3a\u4e86\u907f\u514d\u5728HTTP\u5904\u7406\u51fd\u6570\u4e2d\u51fa\u73b0\u67d0\u4e9b\u610f\u5916\u7684\u95ee\u9898\uff0c\u5982\u679c\u60f3\u5728\u53d1\u751f http.Error
\u540e\u8ba9HTTP\u5904\u7406\u51fd\u6570\u505c\u6b62\uff0c\u90a3\u4e48\u5c31\u4e0d\u8981\u5fd8\u8bb0\u4f7f\u7528return
\u8bed\u53e5\u6765\u963b\u6b62\u540e\u7eed\u4ee3\u7801\u7684\u6267\u884c\u3002
\u5bf9\u4e8e\u751f\u4ea7\u7ea7\u522b\u7684\u5e94\u7528\uff0c\u4e0d\u8981\u4f7f\u7528\u9ed8\u8ba4\u7684HTTP client\u548cserver\u5b9e\u73b0\u3002\u8fd9\u4e9b\u5b9e\u73b0\u7f3a\u5c11\u8d85\u65f6\u548c\u751f\u4ea7\u73af\u5883\u4e2d\u5e94\u8be5\u5f3a\u5236\u4f7f\u7528\u7684\u884c\u4e3a\u3002
"},{"location":"zh/#_10","title":"\u6d4b\u8bd5","text":""},{"location":"zh/#build-tags-82","title":"\u4e0d\u5bf9\u6d4b\u8bd5\u8fdb\u884c\u5206\u7c7b \uff08build tags, \u73af\u5883\u53d8\u91cf\uff0c\u77ed\u6a21\u5f0f\uff09(#82)","text":"\u5bf9\u6d4b\u8bd5\u8fdb\u884c\u5fc5\u8981\u7684\u5206\u7c7b\uff0c\u53ef\u4ee5\u501f\u52a9 build tags\u3001\u73af\u5883\u53d8\u91cf\u4ee5\u53ca\u77ed\u6a21\u5f0f\uff0c\u6765\u4f7f\u5f97\u6d4b\u8bd5\u8fc7\u7a0b\u66f4\u52a0\u9ad8\u6548\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528 build tags \u6216\u73af\u5883\u53d8\u91cf\u6765\u521b\u5efa\u6d4b\u8bd5\u7c7b\u522b\uff08\u4f8b\u5982\u5355\u5143\u6d4b\u8bd5\u4e0e\u96c6\u6210\u6d4b\u8bd5\uff09\uff0c\u5e76\u533a\u5206\u77ed\u6d4b\u8bd5\u4e0e\u957f\u65f6\u95f4\u6d4b\u8bd5\uff0c\u6765\u51b3\u5b9a\u6267\u884c\u54ea\u79cd\u7c7b\u578b\u7684\u3002
ps: \u4e86\u89e3\u4e0bgo build tags\uff0c\u4ee5\u53ca go test -short
\u3002
\u6253\u5f00 -race
\u5f00\u5173\u5728\u7f16\u5199\u5e76\u53d1\u5e94\u7528\u65f6\u975e\u5e38\u91cd\u8981\u3002\u8fd9\u80fd\u5e2e\u52a9\u4f60\u6355\u83b7\u53ef\u80fd\u7684\u6570\u636e\u7ade\u4e89,\u4ece\u800c\u907f\u514d\u8f6f\u4ef6bug\u3002
\u6253\u5f00\u5f00\u5173 -parallel
\u6709\u52a9\u4e8e\u52a0\u901f\u6d4b\u8bd5\u7684\u6267\u884c\uff0c\u7279\u522b\u662f\u6d4b\u8bd5\u4e2d\u5305\u542b\u4e00\u4e9b\u9700\u8981\u957f\u671f\u8fd0\u884c\u7684\u7528\u4f8b\u7684\u65f6\u5019\u3002
\u6253\u5f00\u5f00\u5173 -shuffle
\u80fd\u591f\u6253\u4e71\u6d4b\u8bd5\u7528\u4f8b\u6267\u884c\u7684\u987a\u5e8f\uff0c\u907f\u514d\u4e00\u4e2a\u6d4b\u8bd5\u4f9d\u8d56\u4e8e\u67d0\u4e9b\u4e0d\u7b26\u5408\u771f\u5b9e\u60c5\u51b5\u7684\u9884\u8bbe\uff0c\u6709\u52a9\u4e8e\u53ca\u65e9\u66b4\u6f0fbug\u3002
\u8868\u9a71\u52a8\u7684\u6d4b\u8bd5\u662f\u4e00\u79cd\u6709\u6548\u7684\u65b9\u5f0f,\u53ef\u4ee5\u5c06\u4e00\u7ec4\u76f8\u4f3c\u7684\u6d4b\u8bd5\u5206\u7ec4\u5728\u4e00\u8d77,\u4ee5\u907f\u514d\u4ee3\u7801\u91cd\u590d\u548c\u4f7f\u672a\u6765\u7684\u66f4\u65b0\u66f4\u5bb9\u6613\u5904\u7406\u3002
"},{"location":"zh/#sleep-86","title":"\u5728\u5355\u5143\u6d4b\u8bd5\u4e2d\u6267\u884csleep\u64cd\u4f5c (#86)","text":"\u4f7f\u7528\u540c\u6b65\u7684\u65b9\u5f0f\u3001\u907f\u514dsleep\uff0c\u6765\u5c3d\u91cf\u51cf\u5c11\u6d4b\u8bd5\u7684\u4e0d\u7a33\u5b9a\u6027\u548c\u63d0\u9ad8\u9c81\u68d2\u6027\u3002\u5982\u679c\u65e0\u6cd5\u4f7f\u7528\u540c\u6b65\u624b\u6bb5,\u53ef\u4ee5\u8003\u8651\u91cd\u8bd5\u7684\u65b9\u5f0f\u3002
"},{"location":"zh/#time-api-87","title":"\u6ca1\u6709\u9ad8\u6548\u5730\u5904\u7406 time API (#87)","text":"\u7406\u89e3\u5982\u4f55\u5904\u7406\u4f7f\u7528 time API \u7684\u51fd\u6570\uff0c\u662f\u4f7f\u6d4b\u8bd5\u66f4\u52a0\u7a33\u5b9a\u7684\u53e6\u4e00\u79cd\u65b9\u5f0f\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528\u6807\u51c6\u6280\u672f\uff0c\u4f8b\u5982\u5c06\u65f6\u95f4\u4f5c\u4e3a\u9690\u85cf\u4f9d\u8d56\u9879\u7684\u4e00\u90e8\u5206\u6765\u5904\u7406\uff0c\u6216\u8005\u8981\u6c42\u5ba2\u6237\u7aef\u63d0\u4f9b\u65f6\u95f4\u3002
"},{"location":"zh/#httptest-iotest-88","title":"\u4e0d\u4f7f\u7528\u6d4b\u8bd5\u76f8\u5173\u7684\u5de5\u5177\u5305 (httptest
\u548c iotest
) (#88)","text":"\u8fd9\u4e2a httptest
\u5305\u5bf9\u5904\u7406HTTP\u5e94\u7528\u7a0b\u5e8f\u5f88\u6709\u5e2e\u52a9\u3002\u5b83\u63d0\u4f9b\u4e86\u4e00\u7ec4\u5b9e\u7528\u7a0b\u5e8f\u6765\u6d4b\u8bd5\u5ba2\u6237\u7aef\u548c\u670d\u52a1\u5668\u3002
\u8fd9\u4e2a iotest
\u5305\u6709\u52a9\u4e8e\u7f16\u5199 io.Reader \u5e76\u6d4b\u8bd5\u5e94\u7528\u7a0b\u5e8f\u662f\u5426\u80fd\u591f\u5bb9\u5fcd\u9519\u8bef\u3002
\u4f7f\u7528 time \u65b9\u6cd5\u6765\u4fdd\u6301\u57fa\u51c6\u6d4b\u8bd5\u7684\u51c6\u786e\u6027\u3002
\u589e\u52a0 benchtime
\u6216\u8005\u4f7f\u7528 benchstat
\u7b49\u5de5\u5177\u53ef\u4ee5\u6709\u52a9\u4e8e\u5fae\u57fa\u51c6\u6d4b\u8bd5\u3002
\u5c0f\u5fc3\u5fae\u57fa\u51c6\u6d4b\u8bd5\u7684\u7ed3\u679c,\u5982\u679c\u6700\u7ec8\u8fd0\u884c\u5e94\u7528\u7a0b\u5e8f\u7684\u7cfb\u7edf\u4e0e\u8fd0\u884c\u5fae\u57fa\u51c6\u6d4b\u8bd5\u7684\u7cfb\u7edf\u4e0d\u540c\u3002
\u786e\u4fdd\u6d4b\u8bd5\u51fd\u6570\u662f\u5426\u4f1a\u4ea7\u751f\u4e00\u4e9b\u526f\u4f5c\u7528\uff0c\u9632\u6b62\u7f16\u8bd1\u5668\u4f18\u5316\u6b3a\u9a97\u4f60\u5f97\u5230\u7684\u57fa\u51c6\u6d4b\u8bd5\u7ed3\u679c\u3002
\u4e3a\u4e86\u907f\u514d\u88ab\u89c2\u5bdf\u8005\u6548\u5e94\u6b3a\u9a97,\u5f3a\u5236\u91cd\u65b0\u521b\u5efaCPU\u5bc6\u96c6\u578b\u51fd\u6570\u4f7f\u7528\u7684\u6570\u636e\u3002
"},{"location":"zh/#go-test-90","title":"\u6ca1\u6709\u53bb\u63a2\u7d22go test\u6240\u6709\u7684\u7279\u6027 (#90)","text":"\u4f7f\u7528 -coverprofile
\u53c2\u6570\u53ef\u4ee5\u5feb\u901f\u67e5\u770b\u4ee3\u7801\u7684\u6d4b\u8bd5\u8986\u76d6\u60c5\u51b5\uff0c\u65b9\u4fbf\u5feb\u901f\u67e5\u770b\u54ea\u4e2a\u90e8\u5206\u9700\u8981\u66f4\u591a\u7684\u5173\u6ce8\u3002
\u5355\u5143\u6d4b\u8bd5\u7ec4\u7ec7\u5230\u4e00\u4e2a\u72ec\u7acb\u7684\u5305\u4e2d\uff0c\u5bf9\u4e8e\u5bf9\u5916\u5c42\u66b4\u6f0f\u7684\u63a5\u53e3\uff0c\u9700\u8981\u5199\u4e00\u4e9b\u6d4b\u8bd5\u7528\u4f8b\u3002\u6d4b\u8bd5\u5e94\u8be5\u5173\u6ce8\u516c\u5f00\u7684\u884c\u4e3a\uff0c\u800c\u975e\u5185\u90e8\u5b9e\u73b0\u7ec6\u8282\u3002
\u5904\u7406\u9519\u8bef\u65f6,\u4f7f\u7528 *testing.T
\u53d8\u91cf\u800c\u4e0d\u662f\u7ecf\u5178\u7684 if err != nil
\u53ef\u4ee5\u8ba9\u4ee3\u7801\u66f4\u52a0\u7b80\u6d01\u6613\u8bfb\u3002
\u4f60\u53ef\u4ee5\u4f7f\u7528setup\u548cteardown\u51fd\u6570\u6765\u914d\u7f6e\u4e00\u4e2a\u590d\u6742\u7684\u73af\u5883\uff0c\u6bd4\u5982\u5728\u96c6\u6210\u6d4b\u8bd5\u7684\u60c5\u51b5\u4e0b\u3002
"},{"location":"zh/#_11","title":"\u4e0d\u4f7f\u7528\u6a21\u7cca\u6d4b\u8bd5 (\u793e\u533a\u53cd\u9988\u9519\u8bef)","text":"\u6a21\u7cca\u6d4b\u8bd5\u662f\u4e00\u79cd\u9ad8\u6548\u7684\u7b56\u7565\uff0c\u4f7f\u7528\u5b83\u80fd\u68c0\u6d4b\u51fa\u968f\u673a\u3001\u610f\u6599\u5916\u7684\u548c\u4e00\u4e9b\u6076\u610f\u7684\u6570\u636e\u8f93\u5165\uff0c\u6765\u5b8c\u6210\u4e00\u4e9b\u590d\u6742\u7684\u64cd\u4f5c\u3002
\u89c1: @jeromedoucet
"},{"location":"zh/#_12","title":"\u4f18\u5316\u6280\u672f","text":""},{"location":"zh/#cpu-cache-91","title":"\u4e0d\u7406\u89e3CPU cache (#91)","text":"\u7406\u89e3CPU\u7f13\u5b58\u7684\u4f7f\u7528\u5bf9\u4e8e\u4f18\u5316CPU\u5bc6\u96c6\u578b\u5e94\u7528\u5f88\u91cd\u8981\uff0c\u56e0\u4e3aL1\u7f13\u5b58\u6bd4\u4e3b\u5b58\u5feb50\u5230100\u500d\u3002
\u610f\u8bc6\u5230 cache line \u6982\u5ff5\u5bf9\u4e8e\u7406\u89e3\u5982\u4f55\u5728\u6570\u636e\u5bc6\u96c6\u578b\u5e94\u7528\u4e2d\u7ec4\u7ec7\u6570\u636e\u975e\u5e38\u5173\u952e\u3002CPU \u5e76\u4e0d\u662f\u4e00\u4e2a\u4e00\u4e2a\u5b57\u6765\u83b7\u53d6\u5185\u5b58\u3002\u76f8\u53cd\uff0c\u5b83\u901a\u5e38\u590d\u5236\u4e00\u4e2a 64\u5b57\u8282\u957f\u5ea6\u7684 cache line\u3002\u4e3a\u4e86\u83b7\u5f97\u6bcf\u4e2a cache line \u7684\u6700\u5927\u6548\u7528\uff0c\u9700\u8981\u5b9e\u65bd\u7a7a\u95f4\u5c40\u90e8\u6027\u3002
\u4e00\u7cfb\u5217struct\u5143\u7d20\u6784\u6210\u7684slice vs. \u591a\u4e2aslice\u5b57\u6bb5\u6784\u6210\u7684struct
\u6982\u7387\u6027\u7684\u95ee\u9898
\u63d0\u9ad8CPU\u6267\u884c\u4ee3\u7801\u65f6\u7684\u53ef\u9884\u6d4b\u6027\uff0c\u4e5f\u662f\u4f18\u5316\u67d0\u4e9b\u51fd\u6570\u7684\u4e00\u4e2a\u6709\u6548\u65b9\u6cd5\u3002\u6bd4\u5982\uff0c\u56fa\u5b9a\u6b65\u957f\u6216\u8fde\u7eed\u8bbf\u95ee\u5bf9CPU\u6765\u8bf4\u662f\u53ef\u9884\u6d4b\u7684\uff0c\u4f46\u975e\u8fde\u7eed\u8bbf\u95ee\uff08\u4f8b\u5982\u94fe\u8868\uff09\u5c31\u662f\u4e0d\u53ef\u9884\u6d4b\u7684\u3002
\u8981\u6ce8\u610f\u73b0\u4ee3\u7f13\u5b58\u662f\u5206\u533a\u7684\uff08set associative placement\uff0c\u7ec4\u76f8\u8fde\u6620\u5c04\uff09\uff0c\u8981\u6ce8\u610f\u907f\u514d\u4f7f\u7528 critical stride
\uff0c\u8fd9\u79cd\u6b65\u957f\u60c5\u51b5\u4e0b\u53ea\u80fd\u5229\u7528 cache \u7684\u4e00\u5c0f\u90e8\u5206\u3002
critical stride\uff0c\u8fd9\u79cd\u7c7b\u578b\u7684\u6b65\u957f\uff0c\u6307\u7684\u662f\u5185\u5b58\u8bbf\u95ee\u7684\u6b65\u957f\u521a\u597d\u7b49\u4e8e cache \u5927\u5c0f\u3002\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u53ea\u6709\u5c11\u90e8\u5206 cacheline \u88ab\u5229\u7528\u3002
"},{"location":"zh/#false-sharing-92","title":"\u5199\u7684\u5e76\u53d1\u5904\u7406\u903b\u8f91\u4f1a\u5bfc\u81f4false sharing (#92)","text":"\u4e86\u89e3 CPU \u7f13\u5b58\u7684\u8f83\u4f4e\u5c42\u7684 L1\u3001L2 cache \u4e0d\u4f1a\u5728\u6240\u6709\u6838\u95f4\u5171\u4eab\uff0c\u7f16\u5199\u5e76\u53d1\u5904\u7406\u903b\u8f91\u65f6\u80fd\u907f\u514d\u5199\u51fa\u4e00\u4e9b\u964d\u4f4e\u6027\u80fd\u7684\u95ee\u9898\uff0c\u6bd4\u5982\u4f2a\u5171\u4eab\uff08false sharing\uff09\u3002\u5185\u5b58\u5171\u4eab\u53ea\u662f\u4e00\u79cd\u5047\u8c61\u3002
"},{"location":"zh/#93","title":"\u6ca1\u6709\u8003\u8651\u6307\u4ee4\u7ea7\u7684\u5e76\u884c (#93)","text":"\u4f7f\u7528\u6307\u4ee4\u7ea7\u5e76\u884c\uff08ILP\uff09\u4f18\u5316\u4ee3\u7801\u7684\u7279\u5b9a\u90e8\u5206\uff0c\u4ee5\u5141\u8bb8CPU\u5c3d\u53ef\u80fd\u6267\u884c\u66f4\u591a\u53ef\u4ee5\u5e76\u884c\u6267\u884c\u7684\u6307\u4ee4\u3002\u8bc6\u522b\u6307\u4ee4\u7684\u6570\u636e\u4f9d\u8d56\u95ee\u9898\uff08data hazards\uff09\u662f\u4e3b\u8981\u6b65\u9aa4\u4e4b\u4e00\u3002
"},{"location":"zh/#94","title":"\u4e0d\u4e86\u89e3\u6570\u636e\u5bf9\u9f50 (#94)","text":"\u8bb0\u4f4fGo\u4e2d\u57fa\u672c\u7c7b\u578b\u4e0e\u5176\u81ea\u8eab\u5927\u5c0f\u5bf9\u9f50\uff0c\u4f8b\u5982\uff0c\u6309\u964d\u5e8f\u4ece\u5927\u5230\u5c0f\u91cd\u65b0\u7ec4\u7ec7\u7ed3\u6784\u4f53\u7684\u5b57\u6bb5\u53ef\u4ee5\u5f62\u6210\u66f4\u7d27\u51d1\u7684\u7ed3\u6784\u4f53\uff08\u51cf\u5c11\u5185\u5b58\u5206\u914d\uff0c\u66f4\u597d\u7684\u7a7a\u95f4\u5c40\u90e8\u6027\uff09\uff0c\u8fd9\u6709\u52a9\u4e8e\u907f\u514d\u4e00\u4e9b\u5e38\u89c1\u7684\u9519\u8bef\u3002
"},{"location":"zh/#stack-vs-heap-95","title":"\u4e0d\u4e86\u89e3 stack vs. heap (#95)","text":"\u4e86\u89e3\u5806\u548c\u6808\u4e4b\u95f4\u7684\u533a\u522b\u662f\u5f00\u53d1\u4eba\u5458\u7684\u6838\u5fc3\u77e5\u8bc6\u70b9\uff0c\u7279\u522b\u662f\u8981\u53bb\u4f18\u5316\u4e00\u4e2aGo\u7a0b\u5e8f\u65f6\u3002\u6808\u5206\u914d\u7684\u5f00\u9500\u51e0\u4e4e\u4e3a\u96f6\uff0c\u800c\u5806\u5206\u914d\u5219\u8f83\u6162\uff0c\u5e76\u4e14\u4f9d\u8d56GC\u6765\u6e05\u7406\u5185\u5b58\u3002
"},{"location":"zh/#api-compiler-optimizations-and-syncpool-96","title":"\u4e0d\u77e5\u9053\u5982\u4f55\u51cf\u5c11\u5185\u5b58\u5206\u914d\u6b21\u6570 (API\u8c03\u6574, compiler optimizations, andsync.Pool
) (#96)","text":"\u51cf\u5c11\u5185\u5b58\u5206\u914d\u6b21\u6570\u4e5f\u662f\u4f18\u5316Go\u5e94\u7528\u7684\u4e00\u4e2a\u91cd\u8981\u65b9\u9762\u3002\u8fd9\u53ef\u4ee5\u901a\u8fc7\u4e0d\u540c\u7684\u65b9\u5f0f\u6765\u5b9e\u73b0,\u6bd4\u5982\u4ed4\u7ec6\u8bbe\u8ba1API\u6765\u907f\u514d\u4e0d\u5fc5\u8981\u7684\u62f7\u8d1d\uff0c\u4ee5\u53ca\u4f7f\u7528 sync.Pool
\u6765\u5bf9\u5f85\u5206\u914d\u5bf9\u8c61\u8fdb\u884c\u6c60\u5316\u3002
\u4f7f\u7528\u5feb\u901f\u8def\u5f84\u7684\u5185\u8054\u6280\u672f\u6765\u66f4\u52a0\u6709\u6548\u5730\u51cf\u5c11\u8c03\u7528\u51fd\u6570\u7684\u644a\u9500\u65f6\u95f4\u3002
"},{"location":"zh/#go-98","title":"\u4e0d\u4f7f\u7528Go\u95ee\u9898\u8bca\u65ad\u5de5\u5177 (#98)","text":"\u4e86\u89e3Go profilng\u5de5\u5177\u3001\u6267\u884c\u65f6tracer\u6765\u8f85\u52a9\u5224\u65ad\u4e00\u4e2a\u5e94\u7528\u7a0b\u5e8f\u662f\u5426\u6b63\u5e38\uff0c\u4ee5\u53ca\u5217\u51fa\u9700\u8981\u4f18\u5316\u7684\u90e8\u5206\u3002
"},{"location":"zh/#gc-99","title":"\u4e0d\u7406\u89e3GC\u662f\u5982\u4f55\u5de5\u4f5c\u7684 (#99)","text":"\u7406\u89e3\u5982\u4f55\u8c03\u4f18GC\u80fd\u591f\u5e26\u6765\u5f88\u591a\u6536\u76ca\uff0c\u4f8b\u5982\u6709\u52a9\u4e8e\u66f4\u9ad8\u6548\u5730\u5904\u7406\u7a81\u589e\u7684\u8d1f\u8f7d\u3002
"},{"location":"zh/#dockerk8sgo-100","title":"\u4e0d\u4e86\u89e3Docker\u6216\u8005K8S\u5bf9\u8fd0\u884c\u7684Go\u5e94\u7528\u7684\u6027\u80fd\u5f71\u54cd (#100)","text":"\u4e3a\u4e86\u907f\u514dCPU throttling\uff08CPU\u9650\u9891\uff09\u95ee\u9898\uff0c\u5f53\u6211\u4eec\u5728Docker\u548cKubernetes\u90e8\u7f72\u5e94\u7528\u65f6\uff0c\u8981\u77e5\u9053Go\u8bed\u8a00\u5bf9CFS(\u5b8c\u5168\u516c\u5e73\u8c03\u5ea6\u5668)\u65e0\u611f\u77e5\u3002
"}]} \ No newline at end of file +{"config":{"lang":["en"],"separator":"[\\s\\-]+","pipeline":["stopWordFilter"]},"docs":[{"location":"","title":"Common Go Mistakes","text":"This page is a summary of the mistakes in the 100 Go Mistakes and How to Avoid Them book. Meanwhile, it's also open to the community. If you believe that a common Go mistake should be added, please create an issue.
JobsIs your company hiring? Sponsor this repository and let a significant audience of Go developers (~1k unique visitors per week) know about your opportunities in this section.
BetaYou're viewing a beta version enriched with significantly more content. However, this version is not yet complete, and I'm looking for volunteers to help me summarize the remaining mistakes (GitHub issue #43).
Progress:
"},{"location":"#code-and-project-organization","title":"Code and Project Organization","text":""},{"location":"#unintended-variable-shadowing-1","title":"Unintended variable shadowing (#1)","text":"TL;DRAvoiding shadowed variables can help prevent mistakes like referencing the wrong variable or confusing readers.
Variable shadowing occurs when a variable name is redeclared in an inner block, but this practice is prone to mistakes. Imposing a rule to forbid shadowed variables depends on personal taste. For example, sometimes it can be convenient to reuse an existing variable name like err
for errors. Yet, in general, we should remain cautious because we now know that we can face a scenario where the code compiles, but the variable that receives the value is not the one expected.
Source code
"},{"location":"#unnecessary-nested-code-2","title":"Unnecessary nested code (#2)","text":"TL;DRAvoiding nested levels and keeping the happy path aligned on the left makes building a mental code model easier.
In general, the more nested levels a function requires, the more complex it is to read and understand. Let\u2019s see some different applications of this rule to optimize our code for readability:
if
block returns, we should omit the else
block in all cases. For example, we shouldn\u2019t write:if foo() {\n // ...\n return true\n} else {\n // ...\n}\n
Instead, we omit the else
block like this:
if foo() {\n // ...\n return true\n}\n// ...\n
if s != \"\" {\n // ...\n} else {\n return errors.New(\"empty string\")\n}\n
Here, an empty s
represents the non-happy path. Hence, we should flip the condition like so:
if s == \"\" {\n return errors.New(\"empty string\")\n}\n// ...\n
Writing readable code is an important challenge for every developer. Striving to reduce the number of nested blocks, aligning the happy path on the left, and returning as early as possible are concrete means to improve our code\u2019s readability.
Source code
"},{"location":"#misusing-init-functions-3","title":"Misusing init functions (#3)","text":"TL;DRWhen initializing variables, remember that init functions have limited error handling and make state handling and testing more complex. In most cases, initializations should be handled as specific functions.
An init function is a function used to initialize the state of an application. It takes no arguments and returns no result (a func()
function). When a package is initialized, all the constant and variable declarations in the package are evaluated. Then, the init functions are executed.
Init functions can lead to some issues:
We should be cautious with init functions. They can be helpful in some situations, however, such as defining static configuration. Otherwise, and in most cases, we should handle initializations through ad hoc functions.
Source code
"},{"location":"#overusing-getters-and-setters-4","title":"Overusing getters and setters (#4)","text":"TL;DRForcing the use of getters and setters isn\u2019t idiomatic in Go. Being pragmatic and finding the right balance between efficiency and blindly following certain idioms should be the way to go.
Data encapsulation refers to hiding the values or state of an object. Getters and setters are means to enable encapsulation by providing exported methods on top of unexported object fields.
In Go, there is no automatic support for getters and setters as we see in some languages. It is also considered neither mandatory nor idiomatic to use getters and setters to access struct fields. We shouldn\u2019t overwhelm our code with getters and setters on structs if they don\u2019t bring any value. We should be pragmatic and strive to find the right balance between efficiency and following idioms that are sometimes considered indisputable in other programming paradigms.
Remember that Go is a unique language designed for many characteristics, including simplicity. However, if we find a need for getters and setters or, as mentioned, foresee a future need while guaranteeing forward compatibility, there\u2019s nothing wrong with using them.
"},{"location":"#interface-pollution-5","title":"Interface pollution (#5)","text":"TL;DRAbstractions should be discovered, not created. To prevent unnecessary complexity, create an interface when you need it and not when you foresee needing it, or if you can at least prove the abstraction to be a valid one.
Read the full section here.
Source code
"},{"location":"#interface-on-the-producer-side-6","title":"Interface on the producer side (#6)","text":"TL;DRKeeping interfaces on the client side avoids unnecessary abstractions.
Interfaces are satisfied implicitly in Go, which tends to be a gamechanger compared to languages with an explicit implementation. In most cases, the approach to follow is similar to what we described in the previous section: abstractions should be discovered, not created. This means that it\u2019s not up to the producer to force a given abstraction for all the clients. Instead, it\u2019s up to the client to decide whether it needs some form of abstraction and then determine the best abstraction level for its needs.
An interface should live on the consumer side in most cases. However, in particular contexts (for example, when we know\u2014not foresee\u2014that an abstraction will be helpful for consumers), we may want to have it on the producer side. If we do, we should strive to keep it as minimal as possible, increasing its reusability potential and making it more easily composable.
Source code
"},{"location":"#returning-interfaces-7","title":"Returning interfaces (#7)","text":"TL;DRTo prevent being restricted in terms of flexibility, a function shouldn\u2019t return interfaces but concrete implementations in most cases. Conversely, a function should accept interfaces whenever possible.
In most cases, we shouldn\u2019t return interfaces but concrete implementations. Otherwise, it can make our design more complex due to package dependencies and can restrict flexibility because all the clients would have to rely on the same abstraction. Again, the conclusion is similar to the previous sections: if we know (not foresee) that an abstraction will be helpful for clients, we can consider returning an interface. Otherwise, we shouldn\u2019t force abstractions; they should be discovered by clients. If a client needs to abstract an implementation for whatever reason, it can still do that on the client\u2019s side.
"},{"location":"#any-says-nothing-8","title":"any
says nothing (#8)","text":"TL;DR Only use any
if you need to accept or return any possible type, such as json.Marshal
. Otherwise, any
doesn\u2019t provide meaningful information and can lead to compile-time issues by allowing a caller to call methods with any data type.
The any
type can be helpful if there is a genuine need for accepting or returning any possible type (for instance, when it comes to marshaling or formatting). In general, we should avoid overgeneralizing the code we write at all costs. Perhaps a little bit of duplicated code might occasionally be better if it improves other aspects such as code expressiveness.
Source code
"},{"location":"#being-confused-about-when-to-use-generics-9","title":"Being confused about when to use generics (#9)","text":"TL;DRRelying on generics and type parameters can prevent writing boilerplate code to factor out elements or behaviors. However, do not use type parameters prematurely, but only when you see a concrete need for them. Otherwise, they introduce unnecessary abstractions and complexity.
Read the full section here.
Source code
"},{"location":"#not-being-aware-of-the-possible-problems-with-type-embedding-10","title":"Not being aware of the possible problems with type embedding (#10)","text":"TL;DRUsing type embedding can also help avoid boilerplate code; however, ensure that doing so doesn\u2019t lead to visibility issues where some fields should have remained hidden.
When creating a struct, Go offers the option to embed types. But this can sometimes lead to unexpected behaviors if we don\u2019t understand all the implications of type embedding. Throughout this section, we look at how to embed types, what these bring, and the possible issues.
In Go, a struct field is called embedded if it\u2019s declared without a name. For example,
type Foo struct {\n Bar // Embedded field\n}\n\ntype Bar struct {\n Baz int\n}\n
In the Foo
struct, the Bar
type is declared without an associated name; hence, it\u2019s an embedded field.
We use embedding to promote the fields and methods of an embedded type. Because Bar contains a Baz field, this field is promoted to Foo
. Therefore, Baz becomes available from Foo.
What can we say about type embedding? First, let\u2019s note that it\u2019s rarely a necessity, and it means that whatever the use case, we can probably solve it as well without type embedding. Type embedding is mainly used for convenience: in most cases, to promote behaviors.
If we decide to use type embedding, we need to keep two main constraints in mind:
Foo.Baz()
instead of Foo.Bar.Baz()
). If this is the only rationale, let\u2019s not embed the inner type and use a field instead.Using type embedding consciously by keeping these constraints in mind can help avoid boilerplate code with additional forwarding methods. However, let\u2019s make sure we don\u2019t do it solely for cosmetics and not promote elements that should remain hidden.
Source code
"},{"location":"#not-using-the-functional-options-pattern-11","title":"Not using the functional options pattern (#11)","text":"TL;DRTo handle options conveniently and in an API-friendly manner, use the functional options pattern.
Although there are different implementations with minor variations, the main idea is as follows:
type Option func(options *options) error
. For example, WithPort
accepts an int
argument that represents the port and returns an Option
type that represents how to update the options
struct.type options struct {\n port *int\n}\n\ntype Option func(options *options) error\n\nfunc WithPort(port int) Option {\n return func(options *options) error {\n if port < 0 {\n return errors.New(\"port should be positive\")\n }\n options.port = &port\n return nil\n }\n}\n\nfunc NewServer(addr string, opts ...Option) ( *http.Server, error) {\n var options options\n for _, opt := range opts {\n err := opt(&options)\n if err != nil {\n return nil, err\n }\n }\n\n // At this stage, the options struct is built and contains the config\n // Therefore, we can implement our logic related to port configuration\n var port int\n if options.port == nil {\n port = defaultHTTPPort\n } else {\n if *options.port == 0 {\n port = randomPort()\n } else {\n port = *options.port\n }\n }\n\n // ...\n}\n
The functional options pattern provides a handy and API-friendly way to handle options. Although the builder pattern can be a valid option, it has some minor downsides (having to pass a config struct that can be empty or a less handy way to handle error management) that tend to make the functional options pattern the idiomatic way to deal with these kind of problems in Go.
Source code
"},{"location":"#project-misorganization-project-structure-and-package-organization-12","title":"Project misorganization (project structure and package organization) (#12)","text":"Regarding the overall organization, there are different schools of thought. For example, should we organize our application by context or by layer? It depends on our preferences. We may favor grouping code per context (such as the customer context, the contract context, etc.), or we may favor following hexagonal architecture principles and group per technical layer. If the decision we make fits our use case, it cannot be a wrong decision, as long as we remain consistent with it.
Regarding packages, there are multiple best practices that we should follow. First, we should avoid premature packaging because it might cause us to overcomplicate a project. Sometimes, it\u2019s better to use a simple organization and have our project evolve when we understand what it contains rather than forcing ourselves to make the perfect structure up front. Granularity is another essential thing to consider. We should avoid having dozens of nano packages containing only one or two files. If we do, it\u2019s because we have probably missed some logical connections across these packages, making our project harder for readers to understand. Conversely, we should also avoid huge packages that dilute the meaning of a package name.
Package naming should also be considered with care. As we all know (as developers), naming is hard. To help clients understand a Go project, we should name our packages after what they provide, not what they contain. Also, naming should be meaningful. Therefore, a package name should be short, concise, expressive, and, by convention, a single lowercase word.
Regarding what to export, the rule is pretty straightforward. We should minimize what should be exported as much as possible to reduce the coupling between packages and keep unnecessary exported elements hidden. If we are unsure whether to export an element or not, we should default to not exporting it. Later, if we discover that we need to export it, we can adjust our code. Let\u2019s also keep in mind some exceptions, such as making fields exported so that a struct can be unmarshaled with encoding/json.
Organizing a project isn\u2019t straightforward, but following these rules should help make it easier to maintain. However, remember that consistency is also vital to ease maintainability. Therefore, let\u2019s make sure that we keep things as consistent as possible within a codebase.
NoteIn 2023, the Go team has published an official guideline for organizing / structuring a Go project: go.dev/doc/modules/layout
"},{"location":"#creating-utility-packages-13","title":"Creating utility packages (#13)","text":"TL;DRNaming is a critical piece of application design. Creating packages such as common
, util
, and shared
doesn\u2019t bring much value for the reader. Refactor such packages into meaningful and specific package names.
Also, bear in mind that naming a package after what it provides and not what it contains can be an efficient way to increase its expressiveness.
Source code
"},{"location":"#ignoring-package-name-collisions-14","title":"Ignoring package name collisions (#14)","text":"TL;DRTo avoid naming collisions between variables and packages, leading to confusion or perhaps even bugs, use unique names for each one. If this isn\u2019t feasible, use an import alias to change the qualifier to differentiate the package name from the variable name, or think of a better name.
Package collisions occur when a variable name collides with an existing package name, preventing the package from being reused. We should prevent variable name collisions to avoid ambiguity. If we face a collision, we should either find another meaningful name or use an import alias.
"},{"location":"#missing-code-documentation-15","title":"Missing code documentation (#15)","text":"TL;DRTo help clients and maintainers understand your code\u2019s purpose, document exported elements.
Documentation is an important aspect of coding. It simplifies how clients can consume an API but can also help in maintaining a project. In Go, we should follow some rules to make our code idiomatic:
First, every exported element must be documented. Whether it is a structure, an interface, a function, or something else, if it\u2019s exported, it must be documented. The convention is to add comments, starting with the name of the exported element.
As a convention, each comment should be a complete sentence that ends with punctuation. Also bear in mind that when we document a function (or a method), we should highlight what the function intends to do, not how it does it; this belongs to the core of a function and comments, not documentation. Furthermore, the documentation should ideally provide enough information that the consumer does not have to look at our code to understand how to use an exported element.
When it comes to documenting a variable or a constant, we might be interested in conveying two aspects: its purpose and its content. The former should live as code documentation to be useful for external clients. The latter, though, shouldn\u2019t necessarily be public.
To help clients and maintainers understand a package\u2019s scope, we should also document each package. The convention is to start the comment with // Package
followed by the package name. The first line of a package comment should be concise. That\u2019s because it will appear in the package. Then, we can provide all the information we need in the following lines.
Documenting our code shouldn\u2019t be a constraint. We should take the opportunity to make sure it helps clients and maintainers to understand the purpose of our code.
"},{"location":"#not-using-linters-16","title":"Not using linters (#16)","text":"TL;DRTo improve code quality and consistency, use linters and formatters.
A linter is an automatic tool to analyze code and catch errors. The scope of this section isn\u2019t to give an exhaustive list of the existing linters; otherwise, it will become deprecated pretty quickly. But we should understand and remember why linters are essential for most Go projects.
However, if you\u2019re not a regular user of linters, here is a list that you may want to use daily:
Besides linters, we should also use code formatters to fix code style. Here is a list of some code formatters for you to try:
Meanwhile, we should also look at golangci-lint (https://github.com/golangci/golangci-lint). It\u2019s a linting tool that provides a facade on top of many useful linters and formatters. Also, it allows running the linters in parallel to improve analysis speed, which is quite handy.
Linters and formatters are a powerful way to improve the quality and consistency of our codebase. Let\u2019s take the time to understand which one we should use and make sure we automate their execution (such as a CI or Git precommit hook).
"},{"location":"#data-types","title":"Data Types","text":""},{"location":"#creating-confusion-with-octal-literals-17","title":"Creating confusion with octal literals (#17)","text":"TL;DRWhen reading existing code, bear in mind that integer literals starting with 0
are octal numbers. Also, to improve readability, make octal integers explicit by prefixing them with 0o
.
Octal numbers start with a 0 (e.g., 010
is equal to 8 in base 10). To improve readability and avoid potential mistakes for future code readers, we should make octal numbers explicit using the 0o
prefix (e.g., 0o10
).
We should also note the other integer literal representations:
0b
or 0B
prefix (for example, 0b100
is equal to 4 in base 10)0x
or 0X
prefix (for example, 0xF
is equal to 15 in base 10)i
suffix (for example, 3i
)We can also use an underscore character (_) as a separator for readability. For example, we can write 1 billion this way: 1_000_000_000
. We can also use the underscore character with other representations (for example, 0b00_00_01
).
Source code
"},{"location":"#neglecting-integer-overflows-18","title":"Neglecting integer overflows (#18)","text":"TL;DRBecause integer overflows and underflows are handled silently in Go, you can implement your own functions to catch them.
In Go, an integer overflow that can be detected at compile time generates a compilation error. For example,
var counter int32 = math.MaxInt32 + 1\n
constant 2147483648 overflows int32\n
However, at run time, an integer overflow or underflow is silent; this does not lead to an application panic. It is essential to keep this behavior in mind, because it can lead to sneaky bugs (for example, an integer increment or addition of positive integers that leads to a negative result).
Source code
"},{"location":"#not-understanding-floating-points-19","title":"Not understanding floating-points (#19)","text":"TL;DRMaking floating-point comparisons within a given delta can ensure that your code is portable. When performing addition or subtraction, group the operations with a similar order of magnitude to favor accuracy. Also, perform multiplication and division before addition and subtraction.
In Go, there are two floating-point types (if we omit imaginary numbers): float32 and float64. The concept of a floating point was invented to solve the major problem with integers: their inability to represent fractional values. To avoid bad surprises, we need to know that floating-point arithmetic is an approximation of real arithmetic.
For that, we\u2019ll look at a multiplication example:
var n float32 = 1.0001\nfmt.Println(n * n)\n
We may expect this code to print the result of 1.0001 * 1.0001 = 1.00020001, right? However, running it on most x86 processors prints 1.0002, instead.
Because Go\u2019s float32
and float64
types are approximations, we have to bear a few rules in mind:
Source code
"},{"location":"#not-understanding-slice-length-and-capacity-20","title":"Not understanding slice length and capacity (#20)","text":"TL;DRUnderstanding the difference between slice length and capacity should be part of a Go developer\u2019s core knowledge. The slice length is the number of available elements in the slice, whereas the slice capacity is the number of elements in the backing array.
Read the full section here.
Source code
"},{"location":"#inefficient-slice-initialization-21","title":"Inefficient slice initialization (#21)","text":"TL;DRWhen creating a slice, initialize it with a given length or capacity if its length is already known. This reduces the number of allocations and improves performance.
While initializing a slice using make
, we can provide a length and an optional capacity. Forgetting to pass an appropriate value for both of these parameters when it makes sense is a widespread mistake. Indeed, it can lead to multiple copies and additional effort for the GC to clean the temporary backing arrays. Performance-wise, there\u2019s no good reason not to give the Go runtime a helping hand.
Our options are to allocate a slice with either a given capacity or a given length. Of these two solutions, we have seen that the second tends to be slightly faster. But using a given capacity and append can be easier to implement and read in some contexts.
Source code
"},{"location":"#being-confused-about-nil-vs-empty-slice-22","title":"Being confused about nil vs. empty slice (#22)","text":"TL;DRTo prevent common confusions such as when using the encoding/json
or the reflect
package, you need to understand the difference between nil and empty slices. Both are zero-length, zero-capacity slices, but only a nil slice doesn\u2019t require allocation.
In Go, there is a distinction between nil and empty slices. A nil slice is equals to nil
, whereas an empty slice has a length of zero. A nil slice is empty, but an empty slice isn\u2019t necessarily nil
. Meanwhile, a nil slice doesn\u2019t require any allocation. We have seen throughout this section how to initialize a slice depending on the context by using
var s []string
if we aren\u2019t sure about the final length and the slice can be empty[]string(nil)
as syntactic sugar to create a nil and empty slicemake([]string, length)
if the future length is knownThe last option, []string{}
, should be avoided if we initialize the slice without elements. Finally, let\u2019s check whether the libraries we use make the distinctions between nil and empty slices to prevent unexpected behaviors.
Source code
"},{"location":"#not-properly-checking-if-a-slice-is-empty-23","title":"Not properly checking if a slice is empty (#23)","text":"TL;DRTo check if a slice doesn\u2019t contain any element, check its length. This check works regardless of whether the slice is nil
or empty. The same goes for maps. To design unambiguous APIs, you shouldn\u2019t distinguish between nil and empty slices.
To determine whether a slice has elements, we can either do it by checking if the slice is nil or if its length is equal to 0. Checking the length is the best option to follow as it will cover both if the slice is empty or if the slice is nil.
Meanwhile, when designing interfaces, we should avoid distinguishing nil and empty slices, which leads to subtle programming errors. When returning slices, it should make neither a semantic nor a technical difference if we return a nil or empty slice. Both should mean the same thing for the callers. This principle is the same with maps. To check if a map is empty, check its length, not whether it\u2019s nil.
Source code
"},{"location":"#not-making-slice-copies-correctly-24","title":"Not making slice copies correctly (#24)","text":"TL;DRTo copy one slice to another using the copy
built-in function, remember that the number of copied elements corresponds to the minimum between the two slice\u2019s lengths.
Copying elements from one slice to another is a reasonably frequent operation. When using copy, we must recall that the number of elements copied to the destination corresponds to the minimum between the two slices\u2019 lengths. Also bear in mind that other alternatives exist to copy a slice, so we shouldn\u2019t be surprised if we find them in a codebase.
Source code
"},{"location":"#unexpected-side-effects-using-slice-append-25","title":"Unexpected side effects using slice append (#25)","text":"TL;DRUsing copy or the full slice expression is a way to prevent append
from creating conflicts if two different functions use slices backed by the same array. However, only a slice copy prevents memory leaks if you want to shrink a large slice.
When using slicing, we must remember that we can face a situation leading to unintended side effects. If the resulting slice has a length smaller than its capacity, append can mutate the original slice. If we want to restrict the range of possible side effects, we can use either a slice copy or the full slice expression, which prevents us from doing a copy.
Notes[low:high:max]
(full slice expression): This statement creates a slice similar to the one created with s[low:high]
, except that the resulting slice\u2019s capacity is equal to max - low
.
Source code
"},{"location":"#slices-and-memory-leaks-26","title":"Slices and memory leaks (#26)","text":"TL;DRWorking with a slice of pointers or structs with pointer fields, you can avoid memory leaks by marking as nil the elements excluded by a slicing operation.
"},{"location":"#leaking-capacity","title":"Leaking capacity","text":"Remember that slicing a large slice or array can lead to potential high memory consumption. The remaining space won\u2019t be reclaimed by the GC, and we can keep a large backing array despite using only a few elements. Using a slice copy is the solution to prevent such a case.
Source code
"},{"location":"#slice-and-pointers","title":"Slice and pointers","text":"When we use the slicing operation with pointers or structs with pointer fields, we need to know that the GC won\u2019t reclaim these elements. In that case, the two options are to either perform a copy or explicitly mark the remaining elements or their fields to nil
.
Source code
"},{"location":"#inefficient-map-initialization-27","title":"Inefficient map initialization (#27)","text":"TL;DRWhen creating a map, initialize it with a given length if its length is already known. This reduces the number of allocations and improves performance.
A map provides an unordered collection of key-value pairs in which all the keys are distinct. In Go, a map is based on the hash table data structure. Internally, a hash table is an array of buckets, and each bucket is a pointer to an array of key-value pairs.
If we know up front the number of elements a map will contain, we should create it by providing an initial size. Doing this avoids potential map growth, which is quite heavy computation-wise because it requires reallocating enough space and rebalancing all the elements.
Source code
"},{"location":"#maps-and-memory-leaks-28","title":"Maps and memory leaks (#28)","text":"TL;DRA map can always grow in memory, but it never shrinks. Hence, if it leads to some memory issues, you can try different options, such as forcing Go to recreate the map or using pointers.
Read the full section here.
Source code
"},{"location":"#comparing-values-incorrectly-29","title":"Comparing values incorrectly (#29)","text":"TL;DRTo compare types in Go, you can use the == and != operators if two types are comparable: Booleans, numerals, strings, pointers, channels, and structs are composed entirely of comparable types. Otherwise, you can either use reflect.DeepEqual
and pay the price of reflection or use custom implementations and libraries.
It\u2019s essential to understand how to use ==
and !=
to make comparisons effectively. We can use these operators on operands that are comparable:
We can also use the ?
, >=
, <
, and >
operators with numeric types to compare values and with strings to compare their lexical order.
If operands are not comparable (e.g., slices and maps), we have to use other options such as reflection. Reflection is a form of metaprogramming, and it refers to the ability of an application to introspect and modify its structure and behavior. For example, in Go, we can use reflect.DeepEqual
. This function reports whether two elements are deeply equal by recursively traversing two values. The elements it accepts are basic types plus arrays, structs, slices, maps, pointers, interfaces, and functions. Yet, the main catch is the performance penalty.
If performance is crucial at run time, implementing our custom method might be the best solution. One additional note: we must remember that the standard library has some existing comparison methods. For example, we can use the optimized bytes.Compare
function to compare two slices of bytes. Before implementing a custom method, we need to make sure we don\u2019t reinvent the wheel.
Source code
"},{"location":"#control-structures","title":"Control Structures","text":""},{"location":"#ignoring-that-elements-are-copied-in-range-loops-30","title":"Ignoring that elements are copied inrange
loops (#30)","text":"TL;DR The value element in a range
loop is a copy. Therefore, to mutate a struct, for example, access it via its index or via a classic for
loop (unless the element or the field you want to modify is a pointer).
A range loop allows iterating over different data structures:
Compared to a classic for loop
, a range
loop is a convenient way to iterate over all the elements of one of these data structures, thanks to its concise syntax.
Yet, we should remember that the value element in a range loop is a copy. Therefore, if the value is a struct we need to mutate, we will only update the copy, not the element itself, unless the value or field we modify is a pointer. The favored options are to access the element via the index using a range loop or a classic for loop.
Source code
"},{"location":"#ignoring-how-arguments-are-evaluated-in-range-loops-channels-and-arrays-31","title":"Ignoring how arguments are evaluated inrange
loops (channels and arrays) (#31)","text":"TL;DR Understanding that the expression passed to the range
operator is evaluated only once before the beginning of the loop can help you avoid common mistakes such as inefficient assignment in channel or slice iteration.
The range loop evaluates the provided expression only once, before the beginning of the loop, by doing a copy (regardless of the type). We should remember this behavior to avoid common mistakes that might, for example, lead us to access the wrong element. For example:
a := [3]int{0, 1, 2}\nfor i, v := range a {\n a[2] = 10\n if i == 2 {\n fmt.Println(v)\n }\n}\n
This code updates the last index to 10. However, if we run this code, it does not print 10; it prints 2.
Source code
"},{"location":"#ignoring-the-impacts-of-using-pointer-elements-in-range-loops-32","title":"Ignoring the impacts of using pointer elements inrange
loops (#32)","text":"Warning This mistake isn't relevant anymore from Go 1.22 (details).
"},{"location":"#making-wrong-assumptions-during-map-iterations-ordering-and-map-insert-during-iteration-33","title":"Making wrong assumptions during map iterations (ordering and map insert during iteration) (#33)","text":"TL;DRTo ensure predictable outputs when using maps, remember that a map data structure:
Source code
"},{"location":"#ignoring-how-the-break-statement-works-34","title":"Ignoring how thebreak
statement works (#34)","text":"TL;DR Using break
or continue
with a label enforces breaking a specific statement. This can be helpful with switch
or select
statements inside loops.
A break statement is commonly used to terminate the execution of a loop. When loops are used in conjunction with switch or select, developers frequently make the mistake of breaking the wrong statement. For example:
for i := 0; i < 5; i++ {\n fmt.Printf(\"%d \", i)\n\n switch i {\n default:\n case 2:\n break\n }\n}\n
The break statement doesn\u2019t terminate the for
loop: it terminates the switch
statement, instead. Hence, instead of iterating from 0 to 2, this code iterates from 0 to 4: 0 1 2 3 4
.
One essential rule to keep in mind is that a break
statement terminates the execution of the innermost for
, switch
, or select
statement. In the previous example, it terminates the switch
statement.
To break the loop instead of the switch
statement, the most idiomatic way is to use a label:
loop:\n for i := 0; i < 5; i++ {\n fmt.Printf(\"%d \", i)\n\n switch i {\n default:\n case 2:\n break loop\n }\n }\n
Here, we associate the loop
label with the for
loop. Then, because we provide the loop
label to the break
statement, it breaks the loop, not the switch. Therefore, this new version will print 0 1 2
, as we expected.
Source code
"},{"location":"#using-defer-inside-a-loop-35","title":"Usingdefer
inside a loop (#35)","text":"TL;DR Extracting loop logic inside a function leads to executing a defer
statement at the end of each iteration.
The defer
statement delays a call\u2019s execution until the surrounding function returns. It\u2019s mainly used to reduce boilerplate code. For example, if a resource has to be closed eventually, we can use defer
to avoid repeating the closure calls before every single return
.
One common mistake with defer
is to forget that it schedules a function call when the surrounding function returns. For example:
func readFiles(ch <-chan string) error {\n for path := range ch {\n file, err := os.Open(path)\n if err != nil {\n return err\n }\n\n defer file.Close()\n\n // Do something with file\n }\n return nil\n}\n
The defer
calls are executed not during each loop iteration but when the readFiles
function returns. If readFiles
doesn\u2019t return, the file descriptors will be kept open forever, causing leaks.
One common option to fix this problem is to create a surrounding function after defer
, called during each iteration:
func readFiles(ch <-chan string) error {\n for path := range ch {\n if err := readFile(path); err != nil {\n return err\n }\n }\n return nil\n}\n\nfunc readFile(path string) error {\n file, err := os.Open(path)\n if err != nil {\n return err\n }\n\n defer file.Close()\n\n // Do something with file\n return nil\n}\n
Another solution is to make the readFile
function a closure but intrinsically, this remains the same solution: adding another surrounding function to execute the defer
calls during each iteration.
Source code
"},{"location":"#strings","title":"Strings","text":""},{"location":"#not-understanding-the-concept-of-rune-36","title":"Not understanding the concept of rune (#36)","text":"TL;DRUnderstanding that a rune corresponds to the concept of a Unicode code point and that it can be composed of multiple bytes should be part of the Go developer\u2019s core knowledge to work accurately with strings.
As runes are everywhere in Go, it's important to understand the following:
rune
corresponds to the concept of a Unicode code point, meaning an item represented by a single value.len()
on a string in Go returns the number of bytes, not the number of runes.Source code
"},{"location":"#inaccurate-string-iteration-37","title":"Inaccurate string iteration (#37)","text":"TL;DRIterating on a string with the range
operator iterates on the runes with the index corresponding to the starting index of the rune\u2019s byte sequence. To access a specific rune index (such as the third rune), convert the string into a []rune
.
Iterating on a string is a common operation for developers. Perhaps we want to perform an operation for each rune in the string or implement a custom function to search for a specific substring. In both cases, we have to iterate on the different runes of a string. But it\u2019s easy to get confused about how iteration works.
For example, consider the following example:
s := \"h\u00eallo\"\nfor i := range s {\n fmt.Printf(\"position %d: %c\\n\", i, s[i])\n}\nfmt.Printf(\"len=%d\\n\", len(s))\n
position 0: h\nposition 1: \u00c3\nposition 3: l\nposition 4: l\nposition 5: o\nlen=6\n
Let's highlight three points that might be confusing:
Let\u2019s start with the last observation. We already mentioned that len returns the number of bytes in a string, not the number of runes. Because we assigned a string literal to s
, s
is a UTF-8 string. Meanwhile, the special character \"\u00ea\" isn\u2019t encoded in a single byte; it requires 2 bytes. Therefore, calling len(s)
returns 6.
Meanwhile, in the previous example, we have to understand that we don't iterate over each rune; instead, we iterate over each starting index of a rune:
Printing s[i]
doesn\u2019t print the ith rune; it prints the UTF-8 representation of the byte at index i
. Hence, we printed \"h\u00c3llo\" instead of \"h\u00eallo\".
If we want to print all the different runes, we can either use the value element of the range
operator:
s := \"h\u00eallo\"\nfor i, r := range s {\n fmt.Printf(\"position %d: %c\\n\", i, r)\n}\n
Or, we can convert the string into a slice of runes and iterate over it:
s := \"h\u00eallo\"\nrunes := []rune(s)\nfor i, r := range runes {\n fmt.Printf(\"position %d: %c\\n\", i, r)\n}\n
Note that this solution introduces a run-time overhead compared to the previous one. Indeed, converting a string into a slice of runes requires allocating an additional slice and converting the bytes into runes: an O(n) time complexity with n the number of bytes in the string. Therefore, if we want to iterate over all the runes, we should use the first solution.
However, if we want to access the ith rune of a string with the first option, we don\u2019t have access to the rune index; rather, we know the starting index of a rune in the byte sequence.
s := \"h\u00eallo\"\nr := []rune(s)[4]\nfmt.Printf(\"%c\\n\", r) // o\n
Source code
"},{"location":"#misusing-trim-functions-38","title":"Misusing trim functions (#38)","text":"TL;DRstrings.TrimRight
/strings.TrimLeft
removes all the trailing/leading runes contained in a given set, whereas strings.TrimSuffix
/strings.TrimPrefix
returns a string without a provided suffix/prefix.
For example:
fmt.Println(strings.TrimRight(\"123oxo\", \"xo\"))\n
The example prints 123:
Conversely, strings.TrimLeft
removes all the leading runes contained in a set.
On the other side, strings.TrimSuffix
/ strings.TrimPrefix
returns a string without the provided trailing suffix / prefix.
Source code
"},{"location":"#under-optimized-strings-concatenation-39","title":"Under-optimized strings concatenation (#39)","text":"TL;DRConcatenating a list of strings should be done with strings.Builder
to prevent allocating a new string during each iteration.
Let\u2019s consider a concat
function that concatenates all the string elements of a slice using the +=
operator:
func concat(values []string) string {\n s := \"\"\n for _, value := range values {\n s += value\n }\n return s\n}\n
During each iteration, the +=
operator concatenates s
with the value string. At first sight, this function may not look wrong. But with this implementation, we forget one of the core characteristics of a string: its immutability. Therefore, each iteration doesn\u2019t update s
; it reallocates a new string in memory, which significantly impacts the performance of this function.
Fortunately, there is a solution to deal with this problem, using strings.Builder
:
func concat(values []string) string {\n sb := strings.Builder{}\n for _, value := range values {\n _, _ = sb.WriteString(value)\n }\n return sb.String()\n}\n
During each iteration, we constructed the resulting string by calling the WriteString
method that appends the content of value to its internal buffer, hence minimizing memory copying.
WriteString
returns an error as the second output, but we purposely ignore it. Indeed, this method will never return a non-nil error. So what\u2019s the purpose of this method returning an error as part of its signature? strings.Builder
implements the io.StringWriter
interface, which contains a single method: WriteString(s string) (n int, err error)
. Hence, to comply with this interface, WriteString
must return an error.
Internally, strings.Builder
holds a byte slice. Each call to WriteString
results in a call to append on this slice. There are two impacts. First, this struct shouldn\u2019t be used concurrently, as the calls to append
would lead to race conditions. The second impact is something that we saw in mistake #21, \"Inefficient slice initialization\": if the future length of a slice is already known, we should preallocate it. For that purpose, strings.Builder
exposes a method Grow(n int)
to guarantee space for another n
bytes:
func concat(values []string) string {\n total := 0\n for i := 0; i < len(values); i++ {\n total += len(values[i])\n }\n\n sb := strings.Builder{}\n sb.Grow(total) (2)\n for _, value := range values {\n _, _ = sb.WriteString(value)\n }\n return sb.String()\n}\n
Let\u2019s run a benchmark to compare the three versions (v1 using +=
; v2 using strings.Builder{}
without preallocation; and v3 using strings.Builder{}
with preallocation). The input slice contains 1,000 strings, and each string contains 1,000 bytes:
BenchmarkConcatV1-4 16 72291485 ns/op\nBenchmarkConcatV2-4 1188 878962 ns/op\nBenchmarkConcatV3-4 5922 190340 ns/op\n
As we can see, the latest version is by far the most efficient: 99% faster than v1 and 78% faster than v2.
strings.Builder
is the recommended solution to concatenate a list of strings. Usually, this solution should be used within a loop. Indeed, if we just have to concatenate a few strings (such as a name and a surname), using strings.Builder
is not recommended as doing so will make the code a bit less readable than using the +=
operator or fmt.Sprintf
.
Source code
"},{"location":"#useless-string-conversions-40","title":"Useless string conversions (#40)","text":"TL;DRRemembering that the bytes
package offers the same operations as the strings
package can help avoid extra byte/string conversions.
When choosing to work with a string or a []byte
, most programmers tend to favor strings for convenience. But most I/O is actually done with []byte
. For example, io.Reader
, io.Writer
, and io.ReadAll
work with []byte
, not strings.
When we\u2019re wondering whether we should work with strings or []byte
, let\u2019s recall that working with []byte
isn\u2019t necessarily less convenient. Indeed, all the exported functions of the strings package also have alternatives in the bytes
package: Split
, Count
, Contains
, Index
, and so on. Hence, whether we\u2019re doing I/O or not, we should first check whether we could implement a whole workflow using bytes instead of strings and avoid the price of additional conversions.
Source code
"},{"location":"#substring-and-memory-leaks-41","title":"Substring and memory leaks (#41)","text":"TL;DRUsing copies instead of substrings can prevent memory leaks, as the string returned by a substring operation will be backed by the same byte array.
In mistake #26, \u201cSlices and memory leaks,\u201d we saw how slicing a slice or array may lead to memory leak situations. This principle also applies to string and substring operations.
We need to keep two things in mind while using the substring operation in Go. First, the interval provided is based on the number of bytes, not the number of runes. Second, a substring operation may lead to a memory leak as the resulting substring will share the same backing array as the initial string. The solutions to prevent this case from happening are to perform a string copy manually or to use strings.Clone
from Go 1.18.
Source code
"},{"location":"#functions-and-methods","title":"Functions and Methods","text":""},{"location":"#not-knowing-which-type-of-receiver-to-use-42","title":"Not knowing which type of receiver to use (#42)","text":"TL;DRThe decision whether to use a value or a pointer receiver should be made based on factors such as the type, whether it has to be mutated, whether it contains a field that can\u2019t be copied, and how large the object is. When in doubt, use a pointer receiver.
Choosing between value and pointer receivers isn\u2019t always straightforward. Let\u2019s discuss some of the conditions to help us choose.
A receiver must be a pointer
type slice []int\n\nfunc (s *slice) add(element int) {\n *s = append(*s, element)\n}\n
A receiver should be a pointer
A receiver must be a value
A receiver should be a value
time.Time
.int
, float64
, or string
.Of course, it\u2019s impossible to be exhaustive, as there will always be edge cases, but this section\u2019s goal was to provide guidance to cover most cases. By default, we can choose to go with a value receiver unless there\u2019s a good reason not to do so. In doubt, we should use a pointer receiver.
Source code
"},{"location":"#never-using-named-result-parameters-43","title":"Never using named result parameters (#43)","text":"TL;DRUsing named result parameters can be an efficient way to improve the readability of a function/method, especially if multiple result parameters have the same type. In some cases, this approach can also be convenient because named result parameters are initialized to their zero value. But be cautious about potential side effects.
When we return parameters in a function or a method, we can attach names to these parameters and use them as regular variables. When a result parameter is named, it\u2019s initialized to its zero value when the function/method begins. With named result parameters, we can also call a naked return statement (without arguments). In that case, the current values of the result parameters are used as the returned values.
Here\u2019s an example that uses a named result parameter b
:
func f(a int) (b int) {\n b = a\n return\n}\n
In this example, we attach a name to the result parameter: b
. When we call return without arguments, it returns the current value of b
.
In some cases, named result parameters can also increase readability: for example, if two parameters have the same type. In other cases, they can also be used for convenience. Therefore, we should use named result parameters sparingly when there\u2019s a clear benefit.
Source code
"},{"location":"#unintended-side-effects-with-named-result-parameters-44","title":"Unintended side effects with named result parameters (#44)","text":"TL;DRSee #43.
We mentioned why named result parameters can be useful in some situations. But as these result parameters are initialized to their zero value, using them can sometimes lead to subtle bugs if we\u2019re not careful enough. For example, can you spot what\u2019s wrong with this code?
func (l loc) getCoordinates(ctx context.Context, address string) (\n lat, lng float32, err error) {\n isValid := l.validateAddress(address) (1)\n if !isValid {\n return 0, 0, errors.New(\"invalid address\")\n }\n\n if ctx.Err() != nil { (2)\n return 0, 0, err\n }\n\n // Get and return coordinates\n}\n
The error might not be obvious at first glance. Here, the error returned in the if ctx.Err() != nil
scope is err
. But we haven\u2019t assigned any value to the err
variable. It\u2019s still assigned to the zero value of an error
type: nil
. Hence, this code will always return a nil error.
When using named result parameters, we must recall that each parameter is initialized to its zero value. As we have seen in this section, this can lead to subtle bugs that aren\u2019t always straightforward to spot while reading code. Therefore, let\u2019s remain cautious when using named result parameters, to avoid potential side effects.
Source code
"},{"location":"#returning-a-nil-receiver-45","title":"Returning a nil receiver (#45)","text":"TL;DRWhen returning an interface, be cautious about not returning a nil pointer but an explicit nil value. Otherwise, unintended consequences may occur and the caller will receive a non-nil value.
Source code
"},{"location":"#using-a-filename-as-a-function-input-46","title":"Using a filename as a function input (#46)","text":"TL;DRDesigning functions to receive io.Reader
types instead of filenames improves the reusability of a function and makes testing easier.
Accepting a filename as a function input to read from a file should, in most cases, be considered a code smell (except in specific functions such as os.Open
). Indeed, it makes unit tests more complex because we may have to create multiple files. It also reduces the reusability of a function (although not all functions are meant to be reused). Using the io.Reader
interface abstracts the data source. Regardless of whether the input is a file, a string, an HTTP request, or a gRPC request, the implementation can be reused and easily tested.
Source code
"},{"location":"#ignoring-how-defer-arguments-and-receivers-are-evaluated-argument-evaluation-pointer-and-value-receivers-47","title":"Ignoring howdefer
arguments and receivers are evaluated (argument evaluation, pointer, and value receivers) (#47)","text":"TL;DR Passing a pointer to a defer
function and wrapping a call inside a closure are two possible solutions to overcome the immediate evaluation of arguments and receivers.
In a defer
function the arguments are evaluated right away, not once the surrounding function returns. For example, in this code, we always call notify
and incrementCounter
with the same status: an empty string.
const (\n StatusSuccess = \"success\"\n StatusErrorFoo = \"error_foo\"\n StatusErrorBar = \"error_bar\"\n)\n\nfunc f() error {\n var status string\n defer notify(status)\n defer incrementCounter(status)\n\n if err := foo(); err != nil {\n status = StatusErrorFoo\n return err\n }\n\n if err := bar(); err != nil {\n status = StatusErrorBar\n return err\n }\n\n status = StatusSuccess <5>\n return nil\n}\n
Indeed, we call notify(status)
and incrementCounter(status)
as defer
functions. Therefore, Go will delay these calls to be executed once f
returns with the current value of status at the stage we used defer, hence passing an empty string.
Two leading options if we want to keep using defer
.
The first solution is to pass a string pointer:
func f() error {\n var status string\n defer notify(&status) \n defer incrementCounter(&status)\n\n // The rest of the function unchanged\n}\n
Using defer
evaluates the arguments right away: here, the address of status. Yes, status itself is modified throughout the function, but its address remains constant, regardless of the assignments. Hence, if notify
or incrementCounter
uses the value referenced by the string pointer, it will work as expected. But this solution requires changing the signature of the two functions, which may not always be possible.
There\u2019s another solution: calling a closure (an anonymous function value that references variables from outside its body) as a defer
statement:
func f() error {\n var status string\n defer func() {\n notify(status)\n incrementCounter(status)\n }()\n\n // The rest of the function unchanged\n}\n
Here, we wrap the calls to both notify
and incrementCounter
within a closure. This closure references the status variable from outside its body. Therefore, status
is evaluated once the closure is executed, not when we call defer
. This solution also works and doesn\u2019t require notify
and incrementCounter
to change their signature.
Let's also note this behavior applies with method receiver: the receiver is evaluated immediately.
Source code
"},{"location":"#error-management","title":"Error Management","text":""},{"location":"#panicking-48","title":"Panicking (#48)","text":"TL;DRUsing panic
is an option to deal with errors in Go. However, it should only be used sparingly in unrecoverable conditions: for example, to signal a programmer error or when you fail to load a mandatory dependency.
In Go, panic is a built-in function that stops the ordinary flow:
func main() {\n fmt.Println(\"a\")\n panic(\"foo\")\n fmt.Println(\"b\")\n}\n
This code prints a and then stops before printing b:
a\npanic: foo\n\ngoroutine 1 [running]:\nmain.main()\n main.go:7 +0xb3\n
Panicking in Go should be used sparingly. There are two prominent cases, one to signal a programmer error (e.g., sql.Register
that panics if the driver is nil
or has already been register) and another where our application fails to create a mandatory dependency. Hence, exceptional conditions that lead us to stop the application. In most other cases, error management should be done with a function that returns a proper error type as the last return argument.
Source code
"},{"location":"#ignoring-when-to-wrap-an-error-49","title":"Ignoring when to wrap an error (#49)","text":"TL;DRWrapping an error allows you to mark an error and/or provide additional context. However, error wrapping creates potential coupling as it makes the source error available for the caller. If you want to prevent that, don\u2019t use error wrapping.
Since Go 1.13, the %w directive allows us to wrap errors conveniently. Error wrapping is about wrapping or packing an error inside a wrapper container that also makes the source error available. In general, the two main use cases for error wrapping are the following:
When handling an error, we can decide to wrap it. Wrapping is about adding additional context to an error and/or marking an error as a specific type. If we need to mark an error, we should create a custom error type. However, if we just want to add extra context, we should use fmt.Errorf with the %w directive as it doesn\u2019t require creating a new error type. Yet, error wrapping creates potential coupling as it makes the source error available for the caller. If we want to prevent it, we shouldn\u2019t use error wrapping but error transformation, for example, using fmt.Errorf with the %v directive.
Source code
"},{"location":"#comparing-an-error-type-inaccurately-50","title":"Comparing an error type inaccurately (#50)","text":"TL;DRIf you use Go 1.13 error wrapping with the %w
directive and fmt.Errorf
, comparing an error against a type has to be done using errors.As
. Otherwise, if the returned error you want to check is wrapped, it will fail the checks.
Source code
"},{"location":"#comparing-an-error-value-inaccurately-51","title":"Comparing an error value inaccurately (#51)","text":"TL;DRIf you use Go 1.13 error wrapping with the %w
directive and fmt.Errorf
, comparing an error against or a value has to be done using errors.As
. Otherwise, if the returned error you want to check is wrapped, it will fail the checks.
A sentinel error is an error defined as a global variable:
import \"errors\"\n\nvar ErrFoo = errors.New(\"foo\")\n
In general, the convention is to start with Err
followed by the error type: here, ErrFoo
. A sentinel error conveys an expected error, an error that clients will expect to check. As general guidelines:
var ErrFoo = errors.New(\"foo\")
.type BarError struct { ... }
, with BarError
implementing the error
interface.If we use error wrapping in our application with the %w
directive and fmt.Errorf
, checking an error against a specific value should be done using errors.Is
instead of ==
. Thus, even if the sentinel error is wrapped, errors.Is
can recursively unwrap it and compare each error in the chain against the provided value.
Source code
"},{"location":"#handling-an-error-twice-52","title":"Handling an error twice (#52)","text":"TL;DRIn most situations, an error should be handled only once. Logging an error is handling an error. Therefore, you have to choose between logging or returning an error. In many cases, error wrapping is the solution as it allows you to provide additional context to an error and return the source error.
Handling an error multiple times is a mistake made frequently by developers, not specifically in Go. This can cause situations where the same error is logged multiple times make debugging harder.
Let's remind us that handling an error should be done only once. Logging an error is handling an error. Hence, we should either log or return an error. By doing this, we simplify our code and gain better insights into the error situation. Using error wrapping is the most convenient approach as it allows us to propagate the source error and add context to an error.
Source code
"},{"location":"#not-handling-an-error-53","title":"Not handling an error (#53)","text":"TL;DRIgnoring an error, whether during a function call or in a defer
function, should be done explicitly using the blank identifier. Otherwise, future readers may be confused about whether it was intentional or a miss.
Source code
"},{"location":"#not-handling-defer-errors-54","title":"Not handlingdefer
errors (#54)","text":"TL;DR In many cases, you shouldn\u2019t ignore an error returned by a defer
function. Either handle it directly or propagate it to the caller, depending on the context. If you want to ignore it, use the blank identifier.
Consider the following code:
func f() {\n // ...\n notify() // Error handling is omitted\n}\n\nfunc notify() error {\n // ...\n}\n
From a maintainability perspective, the code can lead to some issues. Let\u2019s consider a new reader looking at it. This reader notices that notify returns an error but that the error isn\u2019t handled by the parent function. How can they guess whether or not handling the error was intentional? How can they know whether the previous developer forgot to handle it or did it purposely?
For these reasons, when we want to ignore an error, there's only one way to do it, using the blank identifier (_
):
_ = notify\n
In terms of compilation and run time, this approach doesn\u2019t change anything compared to the first piece of code. But this new version makes explicit that we aren\u2019t interested in the error. Also, we can add a comment that indicates the rationale for why an error is ignored:
// At-most once delivery.\n// Hence, it's accepted to miss some of them in case of errors.\n_ = notify()\n
Source code
"},{"location":"#concurrency-foundations","title":"Concurrency: Foundations","text":""},{"location":"#mixing-up-concurrency-and-parallelism-55","title":"Mixing up concurrency and parallelism (#55)","text":"TL;DRUnderstanding the fundamental differences between concurrency and parallelism is a cornerstone of the Go developer\u2019s knowledge. Concurrency is about structure, whereas parallelism is about execution.
Concurrency and parallelism are not the same:
In summary, concurrency provides a structure to solve a problem with parts that may be parallelized. Therefore, concurrency enables parallelism.
"},{"location":"#thinking-concurrency-is-always-faster-56","title":"Thinking concurrency is always faster (#56)","text":"TL;DRTo be a proficient developer, you must acknowledge that concurrency isn\u2019t always faster. Solutions involving parallelization of minimal workloads may not necessarily be faster than a sequential implementation. Benchmarking sequential versus concurrent solutions should be the way to validate assumptions.
Read the full section here.
Source code
"},{"location":"#being-puzzled-about-when-to-use-channels-or-mutexes-57","title":"Being puzzled about when to use channels or mutexes (#57)","text":"TL;DRBeing aware of goroutine interactions can also be helpful when deciding between channels and mutexes. In general, parallel goroutines require synchronization and hence mutexes. Conversely, concurrent goroutines generally require coordination and orchestration and hence channels.
Given a concurrency problem, it may not always be clear whether we can implement a solution using channels or mutexes. Because Go promotes sharing memory by communication, one mistake could be to always force the use of channels, regardless of the use case. However, we should see the two options as complementary.
When should we use channels or mutexes? We will use the example in the next figure as a backbone. Our example has three different goroutines with specific relationships:
In general, parallel goroutines have to synchronize: for example, when they need to access or mutate a shared resource such as a slice. Synchronization is enforced with mutexes but not with any channel types (not with buffered channels). Hence, in general, synchronization between parallel goroutines should be achieved via mutexes.
Conversely, in general, concurrent goroutines have to coordinate and orchestrate. For example, if G3 needs to aggregate results from both G1 and G2, G1 and G2 need to signal to G3 that a new intermediate result is available. This coordination falls under the scope of communication\u2014therefore, channels.
Regarding concurrent goroutines, there\u2019s also the case where we want to transfer the ownership of a resource from one step (G1 and G2) to another (G3); for example, if G1 and G2 are enriching a shared resource and at some point, we consider this job as complete. Here, we should use channels to signal that a specific resource is ready and handle the ownership transfer.
Mutexes and channels have different semantics. Whenever we want to share a state or access a shared resource, mutexes ensure exclusive access to this resource. Conversely, channels are a mechanic for signaling with or without data (chan struct{}
or not). Coordination or ownership transfer should be achieved via channels. It\u2019s important to know whether goroutines are parallel or concurrent because, in general, we need mutexes for parallel goroutines and channels for concurrent ones.
Being proficient in concurrency also means understanding that data races and race conditions are different concepts. Data races occur when multiple goroutines simultaneously access the same memory location and at least one of them is writing. Meanwhile, being data-race-free doesn\u2019t necessarily mean deterministic execution. When a behavior depends on the sequence or the timing of events that can\u2019t be controlled, this is a race condition.
Race problems can be among the hardest and most insidious bugs a programmer can face. As Go developers, we must understand crucial aspects such as data races and race conditions, their possible impacts, and how to avoid them.
"},{"location":"#data-race","title":"Data Race","text":"A data race occurs when two or more goroutines simultaneously access the same memory location and at least one is writing. In this case, the result can be hazardous. Even worse, in some situations, the memory location may end up holding a value containing a meaningless combination of bits.
We can prevent a data race from happening using different techniques. For example:
sync/atomic
packageDepending on the operation we want to perform, does a data-race-free application necessarily mean a deterministic result? Not necessarily.
A race condition occurs when the behavior depends on the sequence or the timing of events that can\u2019t be controlled. Here, the timing of events is the goroutines\u2019 execution order.
In summary, when we work in concurrent applications, it\u2019s essential to understand that a data race is different from a race condition. A data race occurs when multiple goroutines simultaneously access the same memory location and at least one of them is writing. A data race means unexpected behavior. However, a data-race-free application doesn\u2019t necessarily mean deterministic results. An application can be free of data races but still have behavior that depends on uncontrolled events (such as goroutine execution, how fast a message is published to a channel, or how long a call to a database lasts); this is a race condition. Understanding both concepts is crucial to becoming proficient in designing concurrent applications.
Source code
"},{"location":"#not-understanding-the-concurrency-impacts-of-a-workload-type-59","title":"Not understanding the concurrency impacts of a workload type (#59)","text":"TL;DRWhen creating a certain number of goroutines, consider the workload type. Creating CPU-bound goroutines means bounding this number close to the GOMAXPROCS
variable (based by default on the number of CPU cores on the host). Creating I/O-bound goroutines depends on other factors, such as the external system.
In programming, the execution time of a workload is limited by one of the following:
The last is the rarest nowadays, given that memory has become very cheap in recent decades. Hence, this section focuses on the two first workload types: CPU- and I/O-bound.
If the workload executed by the workers is I/O-bound, the value mainly depends on the external system. Conversely, if the workload is CPU-bound, the optimal number of goroutines is close to the number of available CPU cores (a best practice can be to use runtime.GOMAXPROCS
). Knowing the workload type (I/O or CPU) is crucial when designing concurrent applications.
Source code
"},{"location":"#misunderstanding-go-contexts-60","title":"Misunderstanding Go contexts (#60)","text":"TL;DRGo contexts are also one of the cornerstones of concurrency in Go. A context allows you to carry a deadline, a cancellation signal, and/or a list of keys-values.
https://pkg.go.dev/context
A Context carries a deadline, a cancellation signal, and other values across API boundaries.
"},{"location":"#deadline","title":"Deadline","text":"A deadline refers to a specific point in time determined with one of the following:
time.Duration
from now (for example, in 250 ms)time.Time
(for example, 2023-02-07 00:00:00 UTC)The semantics of a deadline convey that an ongoing activity should be stopped if this deadline is met. An activity is, for example, an I/O request or a goroutine waiting to receive a message from a channel.
"},{"location":"#cancellation-signals","title":"Cancellation signals","text":"Another use case for Go contexts is to carry a cancellation signal. Let\u2019s imagine that we want to create an application that calls CreateFileWatcher(ctx context.Context, filename string)
within another goroutine. This function creates a specific file watcher that keeps reading from a file and catches updates. When the provided context expires or is canceled, this function handles it to close the file descriptor.
The last use case for Go contexts is to carry a key-value list. What\u2019s the point of having a context carrying a key-value list? Because Go contexts are generic and mainstream, there are infinite use cases.
For example, if we use tracing, we may want different subfunctions to share the same correlation ID. Some developers may consider this ID too invasive to be part of the function signature. In this regard, we could also decide to include it as part of the provided context.
"},{"location":"#catching-a-context-cancellation","title":"Catching a context cancellation","text":"The context.Context
type exports a Done
method that returns a receive-only notification channel: <-chan struct{}
. This channel is closed when the work associated with the context should be canceled. For example,
context.WithCancel
is closed when the cancel function is called.context.WithDeadline
is closed when the deadline has expired.One thing to note is that the internal channel should be closed when a context is canceled or has met a deadline, instead of when it receives a specific value, because the closure of a channel is the only channel action that all the consumer goroutines will receive. This way, all the consumers will be notified once a context is canceled or a deadline is reached.
In summary, to be a proficient Go developer, we have to understand what a context is and how to use it. In general, a function that users wait for should take a context, as doing so allows upstream callers to decide when calling this function should be aborted.
Source code
"},{"location":"#concurrency-practice","title":"Concurrency: Practice","text":""},{"location":"#propagating-an-inappropriate-context-61","title":"Propagating an inappropriate context (#61)","text":"TL;DRUnderstanding the conditions when a context can be canceled should matter when propagating it: for example, an HTTP handler canceling the context when the response has been sent.
In many situations, it is recommended to propagate Go contexts. However, context propagation can sometimes lead to subtle bugs, preventing subfunctions from being correctly executed.
Let\u2019s consider the following example. We expose an HTTP handler that performs some tasks and returns a response. But just before returning the response, we also want to send it to a Kafka topic. We don\u2019t want to penalize the HTTP consumer latency-wise, so we want the publish action to be handled asynchronously within a new goroutine. We assume that we have at our disposal a publish
function that accepts a context so the action of publishing a message can be interrupted if the context is canceled, for example. Here is a possible implementation:
func handler(w http.ResponseWriter, r *http.Request) {\n response, err := doSomeTask(r.Context(), r)\n if err != nil {\n http.Error(w, err.Error(), http.StatusInternalServerError)\n return\n }\n go func() {\n err := publish(r.Context(), response)\n // Do something with err\n }()\n writeResponse(response)\n}\n
What\u2019s wrong with this piece of code? We have to know that the context attached to an HTTP request can cancel in different conditions:
In the first two cases, we probably handle things correctly. For example, if we get a response from doSomeTask but the client has closed the connection, it\u2019s probably OK to call publish with a context already canceled so the message isn\u2019t published. But what about the last case?
When the response has been written to the client, the context associated with the request will be canceled. Therefore, we are facing a race condition:
In the latter case, calling publish will return an error because we returned the HTTP response quickly.
NoteFrom Go 1.21, there is a way to create a new context without cancel. context.WithoutCancel
returns a copy of parent that is not canceled when parent is canceled.
In summary, propagating a context should be done cautiously.
Source code
"},{"location":"#starting-a-goroutine-without-knowing-when-to-stop-it-62","title":"Starting a goroutine without knowing when to stop it (#62)","text":"TL;DRAvoiding leaks means being mindful that whenever a goroutine is started, you should have a plan to stop it eventually.
Goroutines are easy and cheap to start\u2014so easy and cheap that we may not necessarily have a plan for when to stop a new goroutine, which can lead to leaks. Not knowing when to stop a goroutine is a design issue and a common concurrency mistake in Go.
Let\u2019s discuss a concrete example. We will design an application that needs to watch some external configuration (for example, using a database connection). Here\u2019s a first implementation:
func main() {\n newWatcher()\n // Run the application\n}\n\ntype watcher struct { /* Some resources */ }\n\nfunc newWatcher() {\n w := watcher{}\n go w.watch() // Creates a goroutine that watches some external configuration\n}\n
The problem with this code is that when the main goroutine exits (perhaps because of an OS signal or because it has a finite workload), the application is stopped. Hence, the resources created by watcher aren\u2019t closed gracefully. How can we prevent this from happening?
One option could be to pass to newWatcher a context that will be canceled when main returns:
func main() {\n ctx, cancel := context.WithCancel(context.Background())\n defer cancel()\n newWatcher(ctx)\n // Run the application\n}\n\nfunc newWatcher(ctx context.Context) {\n w := watcher{}\n go w.watch(ctx)\n}\n
We propagate the context created to the watch method. When the context is canceled, the watcher struct should close its resources. However, can we guarantee that watch will have time to do so? Absolutely not\u2014and that\u2019s a design flaw.
The problem is that we used signaling to convey that a goroutine had to be stopped. We didn\u2019t block the parent goroutine until the resources had been closed. Let\u2019s make sure we do:
func main() {\n w := newWatcher()\n defer w.close()\n // Run the application\n}\n\nfunc newWatcher() watcher {\n w := watcher{}\n go w.watch()\n return w\n}\n\nfunc (w watcher) close() {\n // Close the resources\n}\n
Instead of signaling watcher
that it\u2019s time to close its resources, we now call this close
method, using defer
to guarantee that the resources are closed before the application exits.
In summary, let\u2019s be mindful that a goroutine is a resource like any other that must eventually be closed to free memory or other resources. Starting a goroutine without knowing when to stop it is a design issue. Whenever a goroutine is started, we should have a clear plan about when it will stop. Last but not least, if a goroutine creates resources and its lifetime is bound to the lifetime of the application, it\u2019s probably safer to wait for this goroutine to complete before exiting the application. This way, we can ensure that the resources can be freed.
Source code
"},{"location":"#not-being-careful-with-goroutines-and-loop-variables-63","title":"Not being careful with goroutines and loop variables (#63)","text":"WarningThis mistake isn't relevant anymore from Go 1.22 (details).
"},{"location":"#expecting-a-deterministic-behavior-using-select-and-channels-64","title":"Expecting a deterministic behavior using select and channels (#64)","text":"TL;DRUnderstanding that select
with multiple channels chooses the case randomly if multiple options are possible prevents making wrong assumptions that can lead to subtle concurrency bugs.
One common mistake made by Go developers while working with channels is to make wrong assumptions about how select behaves with multiple channels.
For example, let's consider the following case (disconnectCh
is a unbuffered channel):
go func() {\n for i := 0; i < 10; i++ {\n messageCh <- i\n }\n disconnectCh <- struct{}{}\n}()\n\nfor {\n select {\n case v := <-messageCh:\n fmt.Println(v)\n case <-disconnectCh:\n fmt.Println(\"disconnection, return\")\n return\n }\n}\n
If we run this example multiple times, the result will be random:
0\n1\n2\ndisconnection, return\n\n0\ndisconnection, return\n
Instead of consuming the 10 messages, we only received a few of them. What\u2019s the reason? It lies in the specification of the select statement with multiple channels (https:// go.dev/ref/spec):
Quote
If one or more of the communications can proceed, a single one that can proceed is chosen via a uniform pseudo-random selection.
Unlike a switch statement, where the first case with a match wins, the select statement selects randomly if multiple options are possible.
This behavior might look odd at first, but there\u2019s a good reason for it: to prevent possible starvation. Suppose the first possible communication chosen is based on the source order. In that case, we may fall into a situation where, for example, we only receive from one channel because of a fast sender. To prevent this, the language designers decided to use a random selection.
When using select
with multiple channels, we must remember that if multiple options are possible, the first case in the source order does not automatically win. Instead, Go selects randomly, so there\u2019s no guarantee about which option will be chosen. To overcome this behavior, in the case of a single producer goroutine, we can use either unbuffered channels or a single channel.
Source code
"},{"location":"#not-using-notification-channels-65","title":"Not using notification channels (#65)","text":"TL;DRSend notifications using a chan struct{}
type.
Channels are a mechanism for communicating across goroutines via signaling. A signal can be either with or without data.
Let\u2019s look at a concrete example. We will create a channel that will notify us whenever a certain disconnection occurs. One idea is to handle it as a chan bool
:
disconnectCh := make(chan bool)\n
Now, let\u2019s say we interact with an API that provides us with such a channel. Because it\u2019s a channel of Booleans, we can receive either true
or false
messages. It\u2019s probably clear what true
conveys. But what does false
mean? Does it mean we haven\u2019t been disconnected? And in this case, how frequently will we receive such a signal? Does it mean we have reconnected? Should we even expect to receive false
? Perhaps we should only expect to receive true
messages.
If that\u2019s the case, meaning we don\u2019t need a specific value to convey some information, we need a channel without data. The idiomatic way to handle it is a channel of empty structs: chan struct{}
.
Using nil channels should be part of your concurrency toolset because it allows you to remove cases from select
statements, for example.
What should this code do?
var ch chan int\n<-ch\n
ch
is a chan int
type. The zero value of a channel being nil, ch
is nil
. The goroutine won\u2019t panic; however, it will block forever.
The principle is the same if we send a message to a nil channel. This goroutine blocks forever:
var ch chan int\nch <- 0\n
Then what\u2019s the purpose of Go allowing messages to be received from or sent to a nil channel? For example, we can use nil channels to implement an idiomatic way to merge two channels:
func merge(ch1, ch2 <-chan int) <-chan int {\n ch := make(chan int, 1)\n\n go func() {\n for ch1 != nil || ch2 != nil { // Continue if at least one channel isn\u2019t nil\n select {\n case v, open := <-ch1:\n if !open {\n ch1 = nil // Assign ch1 to a nil channel once closed\n break\n }\n ch <- v\n case v, open := <-ch2:\n if !open {\n ch2 = nil // Assigns ch2 to a nil channel once closed\n break\n }\n ch <- v\n }\n }\n close(ch)\n }()\n\n return ch\n}\n
This elegant solution relies on nil channels to somehow remove one case from the select
statement.
Let\u2019s keep this idea in mind: nil channels are useful in some conditions and should be part of the Go developer\u2019s toolset when dealing with concurrent code.
Source code
"},{"location":"#being-puzzled-about-channel-size-67","title":"Being puzzled about channel size (#67)","text":"TL;DRCarefully decide on the right channel type to use, given a problem. Only unbuffered channels provide strong synchronization guarantees. For buffered channels, you should have a good reason to specify a channel size other than one.
An unbuffered channel is a channel without any capacity. It can be created by either omitting the size or providing a 0 size:
ch1 := make(chan int)\nch2 := make(chan int, 0)\n
With an unbuffered channel (sometimes called a synchronous channel), the sender will block until the receiver receives data from the channel.
Conversely, a buffered channel has a capacity, and it must be created with a size greater than or equal to 1:
ch3 := make(chan int, 1)\n
With a buffered channel, a sender can send messages while the channel isn\u2019t full. Once the channel is full, it will block until a receiver goroutine receives a message:
ch3 := make(chan int, 1)\nch3 <-1 // Non-blocking\nch3 <-2 // Blocking\n
The first send isn\u2019t blocking, whereas the second one is, as the channel is full at this stage.
What's the main difference between unbuffered and buffered channels:
If we need a buffered channel, what size should we provide?
The default value we should use for buffered channels is its minimum: 1. So, we may approach the problem from this standpoint: is there any good reason not to use a value of 1? Here\u2019s a list of possible cases where we should use another size:
If we are outside of these cases, using a different channel size should be done cautiously. Let\u2019s bear in mind that deciding about an accurate queue size isn\u2019t an easy problem:
Martin Thompson
Queues are typically always close to full or close to empty due to the differences in pace between consumers and producers. They very rarely operate in a balanced middle ground where the rate of production and consumption is evenly matched.
"},{"location":"#forgetting-about-possible-side-effects-with-string-formatting-68","title":"Forgetting about possible side effects with string formatting (#68)","text":"TL;DRBeing aware that string formatting may lead to calling existing functions means watching out for possible deadlocks and other data races.
It\u2019s pretty easy to forget the potential side effects of string formatting while working in a concurrent application.
"},{"location":"#etcd-data-race","title":"etcd data race","text":"github.com/etcd-io/etcd/pull/7816 shows an example of an issue where a map's key was formatted based on a mutable values from a context.
"},{"location":"#deadlock","title":"Deadlock","text":"Can you see what the problem is in this code with a Customer
struct exposing an UpdateAge
method and implementing the fmt.Stringer
interface?
type Customer struct {\n mutex sync.RWMutex // Uses a sync.RWMutex to protect concurrent accesses\n id string\n age int\n}\n\nfunc (c *Customer) UpdateAge(age int) error {\n c.mutex.Lock() // Locks and defers unlock as we update Customer\n defer c.mutex.Unlock()\n\n if age < 0 { // Returns an error if age is negative\n return fmt.Errorf(\"age should be positive for customer %v\", c)\n }\n\n c.age = age\n return nil\n}\n\nfunc (c *Customer) String() string {\n c.mutex.RLock() // Locks and defers unlock as we read Customer\n defer c.mutex.RUnlock()\n return fmt.Sprintf(\"id %s, age %d\", c.id, c.age)\n}\n
The problem here may not be straightforward. If the provided age is negative, we return an error. Because the error is formatted, using the %s
directive on the receiver, it will call the String
method to format Customer
. But because UpdateAge
already acquires the mutex lock, the String
method won\u2019t be able to acquire it. Hence, this leads to a deadlock situation. If all goroutines are also asleep, it leads to a panic.
One possible solution is to restrict the scope of the mutex lock:
func (c *Customer) UpdateAge(age int) error {\n if age < 0 {\n return fmt.Errorf(\"age should be positive for customer %v\", c)\n }\n\n c.mutex.Lock() <1>\n defer c.mutex.Unlock()\n\n c.age = age\n return nil\n}\n
Yet, such an approach isn't always possible. In these conditions, we have to be extremely careful with string formatting.
Another approach is to access the id
field directly:
func (c *Customer) UpdateAge(age int) error {\n c.mutex.Lock()\n defer c.mutex.Unlock()\n\n if age < 0 {\n return fmt.Errorf(\"age should be positive for customer id %s\", c.id)\n }\n\n c.age = age\n return nil\n}\n
In concurrent applications, we should remain cautious about the possible side effects of string formatting.
Source code
"},{"location":"#creating-data-races-with-append-69","title":"Creating data races with append (#69)","text":"TL;DRCalling append
isn\u2019t always data-race-free; hence, it shouldn\u2019t be used concurrently on a shared slice.
Should adding an element to a slice using append
is data-race-free? Spoiler: it depends.
Do you believe this example has a data race?
s := make([]int, 1)\n\ngo func() { // In a new goroutine, appends a new element on s\n s1 := append(s, 1)\n fmt.Println(s1)\n}()\n\ngo func() { // Same\n s2 := append(s, 1)\n fmt.Println(s2)\n}()\n
The answer is no.
In this example, we create a slice with make([]int, 1)
. The code creates a one-length, one-capacity slice. Thus, because the slice is full, using append in each goroutine returns a slice backed by a new array. It doesn\u2019t mutate the existing array; hence, it doesn\u2019t lead to a data race.
Now, let\u2019s run the same example with a slight change in how we initialize s
. Instead of creating a slice with a length of 1, we create it with a length of 0 but a capacity of 1. How about this new example? Does it contain a data race?
s := make([]int, 0, 1)\n\ngo func() { \n s1 := append(s, 1)\n fmt.Println(s1)\n}()\n\ngo func() {\n s2 := append(s, 1)\n fmt.Println(s2)\n}()\n
The answer is yes. We create a slice with make([]int, 0, 1)
. Therefore, the array isn\u2019t full. Both goroutines attempt to update the same index of the backing array (index 1), which is a data race.
How can we prevent the data race if we want both goroutines to work on a slice containing the initial elements of s
plus an extra element? One solution is to create a copy of s
.
We should remember that using append on a shared slice in concurrent applications can lead to a data race. Hence, it should be avoided.
Source code
"},{"location":"#using-mutexes-inaccurately-with-slices-and-maps-70","title":"Using mutexes inaccurately with slices and maps (#70)","text":"TL;DRRemembering that slices and maps are pointers can prevent common data races.
Let's implement a Cache
struct used to handle caching for customer balances. This struct will contain a map of balances per customer ID and a mutex to protect concurrent accesses:
type Cache struct {\n mu sync.RWMutex\n balances map[string]float64\n}\n
Next, we add an AddBalance
method that mutates the balances
map. The mutation is done in a critical section (within a mutex lock and a mutex unlock):
func (c *Cache) AddBalance(id string, balance float64) {\n c.mu.Lock()\n c.balances[id] = balance\n c.mu.Unlock()\n}\n
Meanwhile, we have to implement a method to calculate the average balance for all the customers. One idea is to handle a minimal critical section this way:
func (c *Cache) AverageBalance() float64 {\n c.mu.RLock()\n balances := c.balances // Creates a copy of the balances map\n c.mu.RUnlock()\n\n sum := 0.\n for _, balance := range balances { // Iterates over the copy, outside of the critical section\n sum += balance\n }\n return sum / float64(len(balances))\n}\n
What's the problem with this code?
If we run a test using the -race
flag with two concurrent goroutines, one calling AddBalance
(hence mutating balances) and another calling AverageBalance
, a data race occurs. What\u2019s the problem here?
Internally, a map is a runtime.hmap
struct containing mostly metadata (for example, a counter) and a pointer referencing data buckets. So, balances := c.balances
doesn\u2019t copy the actual data. Therefore, the two goroutines perform operations on the same data set, and one mutates it. Hence, it's a data race.
One possible solution is to protect the whole AverageBalance
function:
func (c *Cache) AverageBalance() float64 {\n c.mu.RLock()\n defer c.mu.RUnlock() // Unlocks when the function returns\n\n sum := 0.\n for _, balance := range c.balances {\n sum += balance\n }\n return sum / float64(len(c.balances))\n}\n
Another option, if the iteration operation isn\u2019t lightweight, is to work on an actual copy of the data and protect only the copy:
func (c *Cache) AverageBalance() float64 {\n c.mu.RLock()\n m := make(map[string]float64, len(c.balances)) // Copies the map\n for k, v := range c.balances {\n m[k] = v\n }\n c.mu.RUnlock()\n\n sum := 0.\n for _, balance := range m {\n sum += balance\n }\n return sum / float64(len(m))\n}\n
Once we have made a deep copy, we release the mutex. The iterations are done on the copy outside of the critical section.
In summary, we have to be careful with the boundaries of a mutex lock. In this section, we have seen why assigning an existing map (or an existing slice) to a map isn\u2019t enough to protect against data races. The new variable, whether a map or a slice, is backed by the same data set. There are two leading solutions to prevent this: protect the whole function, or work on a copy of the actual data. In all cases, let\u2019s be cautious when designing critical sections and make sure the boundaries are accurately defined.
Source code
"},{"location":"#misusing-syncwaitgroup-71","title":"Misusingsync.WaitGroup
(#71)","text":"TL;DR To accurately use sync.WaitGroup
, call the Add
method before spinning up goroutines.
Source code
"},{"location":"#forgetting-about-synccond-72","title":"Forgetting aboutsync.Cond
(#72)","text":"TL;DR You can send repeated notifications to multiple goroutines with sync.Cond
.
Source code
"},{"location":"#not-using-errgroup-73","title":"Not usingerrgroup
(#73)","text":"TL;DR You can synchronize a group of goroutines and handle errors and contexts with the errgroup
package.
Source code
"},{"location":"#copying-a-sync-type-74","title":"Copying async
type (#74)","text":"TL;DR sync
types shouldn\u2019t be copied.
Source code
"},{"location":"#standard-library","title":"Standard Library","text":""},{"location":"#providing-a-wrong-time-duration-75","title":"Providing a wrong time duration (#75)","text":"TL;DRRemain cautious with functions accepting a time.Duration
. Even though passing an integer is allowed, strive to use the time API to prevent any possible confusion.
Many common functions in the standard library accept a time.Duration
, which is an alias for the int64
type. However, one time.Duration
unit represents one nanosecond, instead of one millisecond, as commonly seen in other programming languages. As a result, passing numeric types instead of using the time.Duration
API can lead to unexpected behavior.
A developer with experience in other languages might assume that the following code creates a new time.Ticker
that delivers ticks every second, given the value 1000
:
ticker := time.NewTicker(1000)\nfor {\n select {\n case <-ticker.C:\n // Do something\n }\n}\n
However, because 1,000 time.Duration
units = 1,000 nanoseconds, ticks are delivered every 1,000 nanoseconds = 1 microsecond, not every second as assumed.
We should always use the time.Duration
API to avoid confusion and unexpected behavior:
ticker = time.NewTicker(time.Microsecond)\n// Or\nticker = time.NewTicker(1000 * time.Nanosecond)\n
Source code
"},{"location":"#timeafter-and-memory-leaks-76","title":"time.After
and memory leaks (#76)","text":"TL;DR Avoiding calls to time.After
in repeated functions (such as loops or HTTP handlers) can avoid peak memory consumption. The resources created by time.After
are released only when the timer expires.
Developers often use time.After
in loops or HTTP handlers repeatedly to implement the timing function. But it can lead to unintended peak memory consumption due to the delayed release of resources, just like the following code:
func consumer(ch <-chan Event) {\n for {\n select {\n case event := <-ch:\n handle(event)\n case <-time.After(time.Hour):\n log.Println(\"warning: no messages received\")\n }\n }\n}\n
The source code of the function time.After is as follows:
func After(d Duration) <-chan Time {\n return NewTimer(d).C\n}\n
As we see, it returns receive-only channel.
When time.After
is used in a loop or repeated context, a new channel is created in each iteration. If these channels are not properly closed or if their associated timers are not stopped, they can accumulate and consume memory. The resources associated with each timer and channel are only released when the timer expires or the channel is closed.
To avoid this happening, We can use context's timeout setting instead of time.After
, like below:
func consumer(ch <-chan Event) {\n for {\n ctx, cancel := context.WithTimeout(context.Background(), time.Hour)\n select {\n case event := <-ch:\n cancel()\n handle(event)\n case <-ctx.Done():\n log.Println(\"warning: no messages received\")\n }\n }\n}\n
We can also use time.NewTimer
like so:
func consumer(ch <-chan Event) {\n timerDuration := 1 * time.Hour\n timer := time.NewTimer(timerDuration)\n\n for {\n timer.Reset(timerDuration)\n select {\n case event := <-ch:\n handle(event)\n case <-timer.C:\n log.Println(\"warning: no messages received\")\n }\n }\n}\n
Source code
"},{"location":"#json-handling-common-mistakes-77","title":"JSON handling common mistakes (#77)","text":"Be careful about using embedded fields in Go structs. Doing so may lead to sneaky bugs like an embedded time.Time field implementing the json.Marshaler
interface, hence overriding the default marshaling behavior.
Source code
When comparing two time.Time
structs, recall that time.Time
contains both a wall clock and a monotonic clock, and the comparison using the == operator is done on both clocks.
Source code
any
To avoid wrong assumptions when you provide a map while unmarshaling JSON data, remember that numerics are converted to float64
by default.
Source code
"},{"location":"#common-sql-mistakes-78","title":"Common SQL mistakes (#78)","text":"sql.Open
doesn't necessarily establish connections to a databaseCall the Ping
or PingContext
method if you need to test your configuration and make sure a database is reachable.
Source code
Configure the database connection parameters for production-grade applications.
Using SQL prepared statements makes queries more efficient and more secure.
Source code
Deal with nullable columns in tables using pointers or sql.NullXXX
types.
Source code
Call the Err
method of sql.Rows
after row iterations to ensure that you haven\u2019t missed an error while preparing the next row.
Source code
"},{"location":"#not-closing-transient-resources-http-body-sqlrows-and-osfile-79","title":"Not closing transient resources (HTTP body,sql.Rows
, and os.File
) (#79)","text":"TL;DR Eventually close all structs implementing io.Closer
to avoid possible leaks.
Source code
"},{"location":"#forgetting-the-return-statement-after-replying-to-an-http-request-80","title":"Forgetting the return statement after replying to an HTTP request (#80)","text":"TL;DRTo avoid unexpected behaviors in HTTP handler implementations, make sure you don\u2019t miss the return
statement if you want a handler to stop after http.Error
.
Consider the following HTTP handler that handles an error from foo
using http.Error
:
func handler(w http.ResponseWriter, req *http.Request) {\n err := foo(req)\n if err != nil {\n http.Error(w, \"foo\", http.StatusInternalServerError)\n }\n\n _, _ = w.Write([]byte(\"all good\"))\n w.WriteHeader(http.StatusCreated)\n}\n
If we run this code and err != nil
, the HTTP response would be:
foo\nall good\n
The response contains both the error and success messages, and also the first HTTP status code, 500. There would also be a warning log indicating that we attempted to write the status code multiple times:
2023/10/10 16:45:33 http: superfluous response.WriteHeader call from main.handler (main.go:20)\n
The mistake in this code is that http.Error
does not stop the handler's execution, which means the success message and status code get written in addition to the error. Beyond an incorrect response, failing to return after writing an error can lead to the unwanted execution of code and unexpected side-effects. The following code adds the return
statement following the http.Error
and exhibits the desired behavior when ran:
func handler(w http.ResponseWriter, req *http.Request) {\n err := foo(req)\n if err != nil {\n http.Error(w, \"foo\", http.StatusInternalServerError)\n return // Adds the return statement\n }\n\n _, _ = w.Write([]byte(\"all good\"))\n w.WriteHeader(http.StatusCreated)\n}\n
Source code
"},{"location":"#using-the-default-http-client-and-server-81","title":"Using the default HTTP client and server (#81)","text":"TL;DRFor production-grade applications, don\u2019t use the default HTTP client and server implementations. These implementations are missing timeouts and behaviors that should be mandatory in production.
Source code
"},{"location":"#testing","title":"Testing","text":""},{"location":"#not-categorizing-tests-build-tags-environment-variables-and-short-mode-82","title":"Not categorizing tests (build tags, environment variables, and short mode) (#82)","text":"TL;DRCategorizing tests using build flags, environment variables, or short mode makes the testing process more efficient. You can create test categories using build flags or environment variables (for example, unit versus integration tests) and differentiate short from long-running tests to decide which kinds of tests to execute.
Source code
"},{"location":"#not-enabling-the-race-flag-83","title":"Not enabling the race flag (#83)","text":"TL;DREnabling the -race
flag is highly recommended when writing concurrent applications. Doing so allows you to catch potential data races that can lead to software bugs.
In Go, the race detector isn\u2019t a static analysis tool used during compilation; instead, it\u2019s a tool to find data races that occur at runtime. To enable it, we have to enable the -race flag while compiling or running a test. For example:
go test -race ./...\n
Once the race detector is enabled, the compiler instruments the code to detect data races. Instrumentation refers to a compiler adding extra instructions: here, tracking all memory accesses and recording when and how they occur.
Enabling the race detector adds an overhead in terms of memory and execution time; hence, it's generally recommended to enable it only during local testing or continuous integration, not production.
If a race is detected, Go raises a warning. For example:
package main\n\nimport (\n \"fmt\"\n)\n\nfunc main() {\n i := 0\n go func() { i++ }()\n fmt.Println(i)\n}\n
Runnig this code with the -race
logs the following warning:
==================\nWARNING: DATA RACE\nWrite at 0x00c000026078 by goroutine 7: # (1)\n main.main.func1()\n /tmp/app/main.go:9 +0x4e\n\nPrevious read at 0x00c000026078 by main goroutine: # (2)\n main.main()\n /tmp/app/main.go:10 +0x88\n\nGoroutine 7 (running) created at: # (3)\n main.main()\n /tmp/app/main.go:9 +0x7a\n==================\n
Let\u2019s make sure we are comfortable reading these messages. Go always logs the following:
In addition, if a specific file contains tests that lead to data races, we can (temporarily! ) exclude it from race detection using the !race
build tag:
//go:build !race\n\npackage main\n\nimport (\n \"testing\"\n)\n\nfunc TestFoo(t *testing.T) {\n // ...\n}\n
"},{"location":"#not-using-test-execution-modes-parallel-and-shuffle-84","title":"Not using test execution modes (parallel and shuffle) (#84)","text":"TL;DR Using the -parallel
flag is an efficient way to speed up tests, especially long-running ones. Use the -shuffle
flag to help ensure that a test suite doesn\u2019t rely on wrong assumptions that could hide bugs.
Table-driven tests are an efficient way to group a set of similar tests to prevent code duplication and make future updates easier to handle.
Source code
"},{"location":"#sleeping-in-unit-tests-86","title":"Sleeping in unit tests (#86)","text":"TL;DRAvoid sleeps using synchronization to make a test less flaky and more robust. If synchronization isn\u2019t possible, consider a retry approach.
Source code
"},{"location":"#not-dealing-with-the-time-api-efficiently-87","title":"Not dealing with the time API efficiently (#87)","text":"TL;DRUnderstanding how to deal with functions using the time API is another way to make a test less flaky. You can use standard techniques such as handling the time as part of a hidden dependency or asking clients to provide it.
Source code
"},{"location":"#not-using-testing-utility-packages-httptest-and-iotest-88","title":"Not using testing utility packages (httptest
and iotest
) (#88)","text":"httptest
package is helpful for dealing with HTTP applications. It provides a set of utilities to test both clients and servers.Source code
iotest
package helps write io.Reader and test that an application is tolerant to errors.Source code
"},{"location":"#writing-inaccurate-benchmarks-89","title":"Writing inaccurate benchmarks (#89)","text":"TL;DRRegarding benchmarks:
Read the full section here.
Source code
"},{"location":"#not-exploring-all-the-go-testing-features-90","title":"Not exploring all the Go testing features (#90)","text":"Use code coverage with the -coverprofile
flag to quickly see which part of the code needs more attention.
Place unit tests in a different package to enforce writing tests that focus on an exposed behavior, not internals.
Source code
Handling errors using the *testing.T
variable instead of the classic if err != nil
makes code shorter and easier to read.
Source code
You can use setup and teardown functions to configure a complex environment, such as in the case of integration tests.
Source code
"},{"location":"#not-using-fuzzing-community-mistake","title":"Not using fuzzing (community mistake)","text":"TL;DRFuzzing is an efficient strategy to detect random, unexpected, or malformed inputs to complex functions and methods in order to discover vulnerabilities, bugs, or even potential crashes.
Credits: @jeromedoucet
"},{"location":"#optimizations","title":"Optimizations","text":""},{"location":"#not-understanding-cpu-caches-91","title":"Not understanding CPU caches (#91)","text":"Understanding how to use CPU caches is important for optimizing CPU-bound applications because the L1 cache is about 50 to 100 times faster than the main memory.
Being conscious of the cache line concept is critical to understanding how to organize data in data-intensive applications. A CPU doesn\u2019t fetch memory word by word; instead, it usually copies a memory block to a 64-byte cache line. To get the most out of each individual cache line, enforce spatial locality.
Source code
Source code
Making code predictable for the CPU can also be an efficient way to optimize certain functions. For example, a unit or constant stride is predictable for the CPU, but a non-unit stride (for example, a linked list) isn\u2019t predictable.
Source code
To avoid a critical stride, hence utilizing only a tiny portion of the cache, be aware that caches are partitioned.
"},{"location":"#writing-concurrent-code-that-leads-to-false-sharing-92","title":"Writing concurrent code that leads to false sharing (#92)","text":"TL;DRKnowing that lower levels of CPU caches aren\u2019t shared across all the cores helps avoid performance-degrading patterns such as false sharing while writing concurrency code. Sharing memory is an illusion.
Read the full section here.
Source code
"},{"location":"#not-taking-into-account-instruction-level-parallelism-93","title":"Not taking into account instruction-level parallelism (#93)","text":"TL;DRUse instruction-level parallelism (ILP) to optimize specific parts of your code to allow a CPU to execute as many parallel instructions as possible. Identifying data hazards is one of the main steps.
Source code
"},{"location":"#not-being-aware-of-data-alignment-94","title":"Not being aware of data alignment (#94)","text":"TL;DRYou can avoid common mistakes by remembering that in Go, basic types are aligned with their own size. For example, keep in mind that reorganizing the fields of a struct by size in descending order can lead to more compact structs (less memory allocation and potentially a better spatial locality).
Source code
"},{"location":"#not-understanding-stack-vs-heap-95","title":"Not understanding stack vs. heap (#95)","text":"TL;DRUnderstanding the fundamental differences between heap and stack should also be part of your core knowledge when optimizing a Go application. Stack allocations are almost free, whereas heap allocations are slower and rely on the GC to clean the memory.
Source code
"},{"location":"#not-knowing-how-to-reduce-allocations-api-change-compiler-optimizations-and-syncpool-96","title":"Not knowing how to reduce allocations (API change, compiler optimizations, andsync.Pool
) (#96)","text":"TL;DR Reducing allocations is also an essential aspect of optimizing a Go application. This can be done in different ways, such as designing the API carefully to prevent sharing up, understanding the common Go compiler optimizations, and using sync.Pool
.
Source code
"},{"location":"#not-relying-on-inlining-97","title":"Not relying on inlining (#97)","text":"TL;DRUse the fast-path inlining technique to efficiently reduce the amortized time to call a function.
"},{"location":"#not-using-go-diagnostics-tooling-98","title":"Not using Go diagnostics tooling (#98)","text":"TL;DRRely on profiling and the execution tracer to understand how an application performs and the parts to optimize.
Read the full section here.
"},{"location":"#not-understanding-how-the-gc-works-99","title":"Not understanding how the GC works (#99)","text":"TL;DRUnderstanding how to tune the GC can lead to multiple benefits such as handling sudden load increases more efficiently.
"},{"location":"#not-understanding-the-impacts-of-running-go-in-docker-and-kubernetes-100","title":"Not understanding the impacts of running Go in Docker and Kubernetes (#100)","text":"TL;DRTo help avoid CPU throttling when deployed in Docker and Kubernetes, keep in mind that Go isn\u2019t CFS-aware.
The GOMAXPROCS
variable defines the limit of OS threads in charge of executing user-level code simultaneously. By default, it's set to the number of OS-apparent logical CPU cores.
When running some Go code inside Docker and Kubernetes, we must know that Go isn't CFS-aware (github.com/golang/go/issues/33803). Therefore, GOMAXPROCS
isn't automatically set to the value of spec.containers.resources.limits.cpu
(see Kubernetes Resource Management for Pods and Containers); instead, it's set to the number of logical cores on the host machine. The main implication is that it can lead to an increased tail latency in some specific situations.
One solution is to rely on uber-go/automaxprocs that automatically set GOMAXPROCS
to match the Linux container CPU quota.
Thanks to all the contributors:
"},{"location":"20-slice/","title":"Not understanding slice length and capacity","text":"
It\u2019s pretty common for Go developers to mix slice length and capacity or not understand them thoroughly. Assimilating these two concepts is essential for efficiently handling core operations such as slice initialization and adding elements with append, copying, or slicing. This misunderstanding can lead to using slices suboptimally or even to memory leaks.
In Go, a slice is backed by an array. That means the slice\u2019s data is stored contiguously in an array data structure. A slice also handles the logic of adding an element if the backing array is full or shrinking the backing array if it\u2019s almost empty.
Internally, a slice holds a pointer to the backing array plus a length and a capacity. The length is the number of elements the slice contains, whereas the capacity is the number of elements in the backing array, counting from the first element in the slice. Let\u2019s go through a few examples to make things clearer. First, let\u2019s initialize a slice with a given length and capacity:
s := make([]int, 3, 6) // Three-length, six-capacity slice\n
The first argument, representing the length, is mandatory. However, the second argument representing the capacity is optional. Figure 1 shows the result of this code in memory.
Figure 1: A three-length, six-capacity slice.
In this case, make
creates an array of six elements (the capacity). But because the length was set to 3, Go initializes only the first three elements. Also, because the slice is an []int
type, the first three elements are initialized to the zeroed value of an int
: 0. The grayed elements are allocated but not yet used.
If we print this slice, we get the elements within the range of the length, [0 0 0]
. If we set s[1]
to 1, the second element of the slice updates without impacting its length or capacity. Figure 2 illustrates this.
Figure 2: Updating the slice\u2019s second element: s[1] = 1.
However, accessing an element outside the length range is forbidden, even though it\u2019s already allocated in memory. For example, s[4]
= 0 would lead to the following panic:
panic: runtime error: index out of range [4] with length 3\n
How can we use the remaining space of the slice? By using the append
built-in function:
s = append(s, 2)\n
This code appends to the existing s
slice a new element. It uses the first grayed element (which was allocated but not yet used) to store element 2, as figure 3 shows.
Figure 3: Appending an element to s.
The length of the slice is updated from 3 to 4 because the slice now contains four elements. Now, what happens if we add three more elements so that the backing array isn\u2019t large enough?
s = append(s, 3, 4, 5)\nfmt.Println(s)\n
If we run this code, we see that the slice was able to cope with our request:
[0 1 0 2 3 4 5]\n
Because an array is a fixed-size structure, it can store the new elements until element 4. When we want to insert element 5, the array is already full: Go internally creates another array by doubling the capacity, copying all the elements, and then inserting element 5. Figure 4 shows this process.
Figure 4: Because the initial backing array is full, Go creates another array and copies all the elements.
The slice now references the new backing array. What will happen to the previous backing array? If it\u2019s no longer referenced, it\u2019s eventually freed by the garbage collector (GC) if allocated on the heap. (We discuss heap memory in mistake #95, \u201cNot understanding stack vs. heap,\u201d and we look at how the GC works in mistake #99, \u201cNot understanding how the GC works.\u201d)
What happens with slicing? Slicing is an operation done on an array or a slice, providing a half-open range; the first index is included, whereas the second is excluded. The following example shows the impact, and figure 5 displays the result in memory:
s1 := make([]int, 3, 6) // Three-length, six-capacity slice\ns2 := s1[1:3] // Slicing from indices 1 to 3\n
Figure 5: The slices s1 and s2 reference the same backing array with different lengths and capacities.
First, s1
is created as a three-length, six-capacity slice. When s2
is created by slicing s1
, both slices reference the same backing array. However, s2
starts from a different index, 1. Therefore, its length and capacity (a two-length, five-capacity slice) differ from s1. If we update s1[1]
or s2[0]
, the change is made to the same array, hence, visible in both slices, as figure 6 shows.
Figure 6: Because s1 and s2 are backed by the same array, updating a common element makes the change visible in both slices.
Now, what happens if we append an element to s2
? Does the following code change s1
as well?
s2 = append(s2, 2)\n
The shared backing array is modified, but only the length of s2
changes. Figure 7 shows the result of appending an element to s2
.
Figure 7: Appending an element to s2.
s1
remains a three-length, six-capacity slice. Therefore, if we print s1
and s2
, the added element is only visible for s2
:
s1=[0 1 0], s2=[1 0 2]\n
It\u2019s important to understand this behavior so that we don\u2019t make wrong assumptions while using append.
NoteIn these examples, the backing array is internal and not available directly to the Go developer. The only exception is when a slice is created from slicing an existing array.
One last thing to note: what if we keep appending elements to s2
until the backing array is full? What will the state be, memory-wise? Let\u2019s add three more elements so that the backing array will not have enough capacity:
s2 = append(s2, 3)\ns2 = append(s2, 4) // At this stage, the backing is already full\ns2 = append(s2, 5)\n
This code leads to creating another backing array. Figure 8 displays the results in memory.
Figure 8: Appending elements to s2 until the backing array is full.
s1
and s2
now reference two different arrays. As s1
is still a three-length, six-capacity slice, it still has some available buffer, so it keeps referencing the initial array. Also, the new backing array was made by copying the initial one from the first index of s2
. That\u2019s why the new array starts with element 1, not 0.
To summarize, the slice length is the number of available elements in the slice, whereas the slice capacity is the number of elements in the backing array. Adding an element to a full slice (length == capacity) leads to creating a new backing array with a new capacity, copying all the elements from the previous array, and updating the slice pointer to the new array.
"},{"location":"28-maps-memory-leaks/","title":"Maps and memory leaks","text":"When working with maps in Go, we need to understand some important characteristics of how a map grows and shrinks. Let\u2019s delve into this to prevent issues that can cause memory leaks.
First, to view a concrete example of this problem, let\u2019s design a scenario where we will work with the following map:
m := make(map[int][128]byte)\n
Each value of m is an array of 128 bytes. We will do the following:
After each step, we want to print the size of the heap (using a printAlloc
utility function). This shows us how this example behaves memory-wise:
func main() {\n n := 1_000_000\n m := make(map[int][128]byte)\n printAlloc()\n\n for i := 0; i < n; i++ { // Adds 1 million elements\n m[i] = [128]byte{}\n }\n printAlloc()\n\n for i := 0; i < n; i++ { // Deletes 1 million elements\n delete(m, i)\n }\n\n runtime.GC() // Triggers a manual GC\n printAlloc()\n runtime.KeepAlive(m) // Keeps a reference to m so that the map isn\u2019t collected\n}\n\nfunc printAlloc() {\n var m runtime.MemStats\n runtime.ReadMemStats(&m)\n fmt.Printf(\"%d MB\\n\", m.Alloc/(1024*1024))\n}\n
We allocate an empty map, add 1 million elements, remove 1 million elements, and then run a GC. We also make sure to keep a reference to the map using runtime.KeepAlive
so that the map isn\u2019t collected as well. Let\u2019s run this example:
0 MB <-- After m is allocated\n461 MB <-- After we add 1 million elements\n293 MB <-- After we remove 1 million elements\n
What can we observe? At first, the heap size is minimal. Then it grows significantly after having added 1 million elements to the map. But if we expected the heap size to decrease after removing all the elements, this isn\u2019t how maps work in Go. In the end, even though the GC has collected all the elements, the heap size is still 293 MB. So the memory shrunk, but not as we might have expected. What\u2019s the rationale? We need to delve into how a map works in Go.
A map provides an unordered collection of key-value pairs in which all the keys are distinct. In Go, a map is based on the hash table data structure: an array where each element is a pointer to a bucket of key-value pairs, as shown in figure 1.
Figure 1: A hash table example with a focus on bucket 0.
Each bucket is a fixed-size array of eight elements. In the case of an insertion into a bucket that is already full (a bucket overflow), Go creates another bucket of eight elements and links the previous one to it. Figure 2 shows an example:
Figure 2: In case of a bucket overflow, Go allocates a new bucket and links the previous bucket to it.
Under the hood, a Go map is a pointer to a runtime.hmap struct. This struct contains multiple fields, including a B field, giving the number of buckets in the map:
type hmap struct {\n B uint8 // log_2 of # of buckets\n // (can hold up to loadFactor * 2^B items)\n // ...\n}\n
After adding 1 million elements, the value of B equals 18, which means 2\u00b9\u2078 = 262,144 buckets. When we remove 1 million elements, what\u2019s the value of B? Still 18. Hence, the map still contains the same number of buckets.
The reason is that the number of buckets in a map cannot shrink. Therefore, removing elements from a map doesn\u2019t impact the number of existing buckets; it just zeroes the slots in the buckets. A map can only grow and have more buckets; it never shrinks.
In the previous example, we went from 461 MB to 293 MB because the elements were collected, but running the GC didn\u2019t impact the map itself. Even the number of extra buckets (the buckets created because of overflows) remains the same.
Let\u2019s take a step back and discuss when the fact that a map cannot shrink can be a problem. Imagine building a cache using a map[int][128]byte
. This map holds per customer ID (the int
), a sequence of 128 bytes. Now, suppose we want to save the last 1,000 customers. The map size will remain constant, so we shouldn\u2019t worry about the fact that a map cannot shrink.
However, let\u2019s say we want to store one hour of data. Meanwhile, our company has decided to have a big promotion for Black Friday: in one hour, we may have millions of customers connected to our system. But a few days after Black Friday, our map will contain the same number of buckets as during the peak time. This explains why we can experience high memory consumption that doesn\u2019t significantly decrease in such a scenario.
What are the solutions if we don\u2019t want to manually restart our service to clean the amount of memory consumed by the map? One solution could be to re-create a copy of the current map at a regular pace. For example, every hour, we can build a new map, copy all the elements, and release the previous one. The main drawback of this option is that following the copy and until the next garbage collection, we may consume twice the current memory for a short period.
Another solution would be to change the map type to store an array pointer: map[int]*[128]byte
. It doesn\u2019t solve the fact that we will have a significant number of buckets; however, each bucket entry will reserve the size of a pointer for the value instead of 128 bytes (8 bytes on 64-bit systems and 4 bytes on 32-bit systems).
Coming back to the original scenario, let\u2019s compare the memory consumption for each map type following each step. The following table shows the comparison.
Stepmap[int][128]byte
map[int]*[128]byte
Allocate an empty map 0 MB 0 MB Add 1 million elements 461 MB 182 MB Remove all the elements and run a GC 293 MB 38 MB Note If a key or a value is over 128 bytes, Go won\u2019t store it directly in the map bucket. Instead, Go stores a pointer to reference the key or the value.
As we have seen, adding n elements to a map and then deleting all the elements means keeping the same number of buckets in memory. So, we must remember that because a Go map can only grow in size, so does its memory consumption. There is no automated strategy to shrink it. If this leads to high memory consumption, we can try different options such as forcing Go to re-create the map or using pointers to check if it can be optimized.
"},{"location":"5-interface-pollution/","title":"Interface pollution","text":"Interfaces are one of the cornerstones of the Go language when designing and structuring our code. However, like many tools or concepts, abusing them is generally not a good idea. Interface pollution is about overwhelming our code with unnecessary abstractions, making it harder to understand. It\u2019s a common mistake made by developers coming from another language with different habits. Before delving into the topic, let\u2019s refresh our minds about Go\u2019s interfaces. Then, we will see when it\u2019s appropriate to use interfaces and when it may be considered pollution.
"},{"location":"5-interface-pollution/#concepts","title":"Concepts","text":"An interface provides a way to specify the behavior of an object. We use interfaces to create common abstractions that multiple objects can implement. What makes Go interfaces so different is that they are satisfied implicitly. There is no explicit keyword like implements
to mark that an object X implements interface Y.
To understand what makes interfaces so powerful, we will dig into two popular ones from the standard library: io.Reader
and io.Writer
. The io
package provides abstractions for I/O primitives. Among these abstractions, io.Reader
relates to reading data from a data source and io.Writer
to writing data to a target, as represented in the next figure:
The io.Reader
contains a single Read method:
type Reader interface {\n Read(p []byte) (n int, err error)\n}\n
Custom implementations of the io.Reader
interface should accept a slice of bytes, filling it with its data and returning either the number of bytes read or an error.
On the other hand, io.Writer
defines a single method, Write:
type Writer interface {\n Write(p []byte) (n int, err error)\n}\n
Custom implementations of io.Writer
should write the data coming from a slice to a target and return either the number of bytes written or an error. Therefore, both interfaces provide fundamental abstractions:
io.Reader
reads data from a sourceio.Writer
writes data to a targetWhat is the rationale for having these two interfaces in the language? What is the point of creating these abstractions?
Let\u2019s assume we need to implement a function that should copy the content of one file to another. We could create a specific function that would take as input two *os.Files
. Or, we can choose to create a more generic function using io.Reader
and io.Writer
abstractions:
func copySourceToDest(source io.Reader, dest io.Writer) error {\n // ...\n}\n
This function would work with *os.File
parameters (as *os.File
implements both io.Reader
and io.Writer
) and any other type that would implement these interfaces. For example, we could create our own io.Writer
that writes to a database, and the code would remain the same. It increases the genericity of the function; hence, its reusability.
Furthermore, writing a unit test for this function is easier because, instead of having to handle files, we can use the strings
and bytes
packages that provide helpful implementations:
func TestCopySourceToDest(t *testing.T) {\n const input = \"foo\"\n source := strings.NewReader(input) // Creates an io.Reader\n dest := bytes.NewBuffer(make([]byte, 0)) // Creates an io.Writer\n\n err := copySourceToDest(source, dest) // Calls copySourceToDest from a *strings.Reader and a *bytes.Buffer\n if err != nil {\n t.FailNow()\n }\n\n got := dest.String()\n if got != input {\n t.Errorf(\"expected: %s, got: %s\", input, got)\n }\n}\n
In the example, source is a *strings.Reader
, whereas dest is a *bytes.Buffer
. Here, we test the behavior of copySourceToDest
without creating any files.
While designing interfaces, the granularity (how many methods the interface contains) is also something to keep in mind. A known proverb in Go relates to how big an interface should be:
Rob Pike
The bigger the interface, the weaker the abstraction.
Indeed, adding methods to an interface can decrease its level of reusability. io.Reader
and io.Writer
are powerful abstractions because they cannot get any simpler. Furthermore, we can also combine fine-grained interfaces to create higher-level abstractions. This is the case with io.ReadWriter
, which combines the reader and writer behaviors:
type ReadWriter interface {\n Reader\n Writer\n}\n
Note As Einstein said, \u201cEverything should be made as simple as possible, but no simpler.\u201d Applied to interfaces, this denotes that finding the perfect granularity for an interface isn\u2019t necessarily a straightforward process.
Let\u2019s now discuss common cases where interfaces are recommended.
"},{"location":"5-interface-pollution/#when-to-use-interfaces","title":"When to use interfaces","text":"When should we create interfaces in Go? Let\u2019s look at three concrete use cases where interfaces are usually considered to bring value. Note that the goal isn\u2019t to be exhaustive because the more cases we add, the more they would depend on the context. However, these three cases should give us a general idea:
The first option we will discuss is to use interfaces when multiple types implement a common behavior. In such a case, we can factor out the behavior inside an interface. If we look at the standard library, we can find many examples of such a use case. For example, sorting a collection can be factored out via three methods:
Hence, the following interface was added to the sort
package:
type Interface interface {\n Len() int // Number of elements\n Less(i, j int) bool // Checks two elements\n Swap(i, j int) // Swaps two elements\n}\n
This interface has a strong potential for reusability because it encompasses the common behavior to sort any collection that is index-based.
Throughout the sort
package, we can find dozens of implementations. If at some point we compute a collection of integers, for example, and we want to sort it, are we necessarily interested in the implementation type? Is it important whether the sorting algorithm is a merge sort or a quicksort? In many cases, we don\u2019t care. Hence, the sorting behavior can be abstracted, and we can depend on the sort.Interface
.
Finding the right abstraction to factor out a behavior can also bring many benefits. For example, the sort
package provides utility functions that also rely on sort.Interface
, such as checking whether a collection is already sorted. For instance:
func IsSorted(data Interface) bool {\n n := data.Len()\n for i := n - 1; i > 0; i-- {\n if data.Less(i, i-1) {\n return false\n }\n }\n return true\n}\n
Because sort.Interface
is the right level of abstraction, it makes it highly valuable.
Let\u2019s now see another main use case when using interfaces.
"},{"location":"5-interface-pollution/#decoupling","title":"Decoupling","text":"Another important use case is about decoupling our code from an implementation. If we rely on an abstraction instead of a concrete implementation, the implementation itself can be replaced with another without even having to change our code. This is the Liskov Substitution Principle (the L in Robert C. Martin\u2019s SOLID design principles).
One benefit of decoupling can be related to unit testing. Let\u2019s assume we want to implement a CreateNewCustomer
method that creates a new customer and stores it. We decide to rely on the concrete implementation directly (let\u2019s say a mysql.Store
struct):
type CustomerService struct {\n store mysql.Store // Depends on the concrete implementation\n}\n\nfunc (cs CustomerService) CreateNewCustomer(id string) error {\n customer := Customer{id: id}\n return cs.store.StoreCustomer(customer)\n}\n
Now, what if we want to test this method? Because customerService
relies on the actual implementation to store a Customer
, we are obliged to test it through integration tests, which requires spinning up a MySQL instance (unless we use an alternative technique such as go-sqlmock
, but this isn\u2019t the scope of this section). Although integration tests are helpful, that\u2019s not always what we want to do. To give us more flexibility, we should decouple CustomerService
from the actual implementation, which can be done via an interface like so:
type customerStorer interface { // Creates a storage abstraction\n StoreCustomer(Customer) error\n}\n\ntype CustomerService struct {\n storer customerStorer // Decouples CustomerService from the actual implementation\n}\n\nfunc (cs CustomerService) CreateNewCustomer(id string) error {\n customer := Customer{id: id}\n return cs.storer.StoreCustomer(customer)\n}\n
Because storing a customer is now done via an interface, this gives us more flexibility in how we want to test the method. For instance, we can:
Let\u2019s now discuss another use case: to restrict a behavior.
"},{"location":"5-interface-pollution/#restricting-behavior","title":"Restricting behavior","text":"The last use case we will discuss can be pretty counterintuitive at first sight. It\u2019s about restricting a type to a specific behavior. Let\u2019s imagine we implement a custom configuration package to deal with dynamic configuration. We create a specific container for int
configurations via an IntConfig
struct that also exposes two methods: Get
and Set
. Here\u2019s how that code would look:
type IntConfig struct {\n // ...\n}\n\nfunc (c *IntConfig) Get() int {\n // Retrieve configuration\n}\n\nfunc (c *IntConfig) Set(value int) {\n // Update configuration\n}\n
Now, suppose we receive an IntConfig
that holds some specific configuration, such as a threshold. Yet, in our code, we are only interested in retrieving the configuration value, and we want to prevent updating it. How can we enforce that, semantically, this configuration is read-only, if we don\u2019t want to change our configuration package? By creating an abstraction that restricts the behavior to retrieving only a config value:
type intConfigGetter interface {\n Get() int\n}\n
Then, in our code, we can rely on intConfigGetter
instead of the concrete implementation:
type Foo struct {\n threshold intConfigGetter\n}\n\nfunc NewFoo(threshold intConfigGetter) Foo { // Injects the configuration getter\n return Foo{threshold: threshold}\n}\n\nfunc (f Foo) Bar() {\n threshold := f.threshold.Get() // Reads the configuration\n // ...\n}\n
In this example, the configuration getter is injected into the NewFoo
factory method. It doesn\u2019t impact a client of this function because it can still pass an IntConfig
struct as it implements intConfigGetter
. Then, we can only read the configuration in the Bar
method, not modify it. Therefore, we can also use interfaces to restrict a type to a specific behavior for various reasons, such as semantics enforcement.
In this section, we saw three potential use cases where interfaces are generally considered as bringing value: factoring out a common behavior, creating some decoupling, and restricting a type to a certain behavior. Again, this list isn\u2019t exhaustive, but it should give us a general understanding of when interfaces are helpful in Go.
Now, let\u2019s finish this section and discuss the problems with interface pollution.
"},{"location":"5-interface-pollution/#interface-pollution_1","title":"Interface pollution","text":"It\u2019s fairly common to see interfaces being overused in Go projects. Perhaps the developer\u2019s background was C# or Java, and they found it natural to create interfaces before concrete types. However, this isn\u2019t how things should work in Go.
As we discussed, interfaces are made to create abstractions. And the main caveat when programming meets abstractions is remembering that abstractions should be discovered, not created. What does this mean? It means we shouldn\u2019t start creating abstractions in our code if there is no immediate reason to do so. We shouldn\u2019t design with interfaces but wait for a concrete need. Said differently, we should create an interface when we need it, not when we foresee that we could need it.
What\u2019s the main problem if we overuse interfaces? The answer is that they make the code flow more complex. Adding a useless level of indirection doesn\u2019t bring any value; it creates a worthless abstraction making the code more difficult to read, understand, and reason about. If we don\u2019t have a strong reason for adding an interface and it\u2019s unclear how an interface makes a code better, we should challenge this interface\u2019s purpose. Why not call the implementation directly?
NoteWe may also experience performance overhead when calling a method through an interface. It requires a lookup in a hash table\u2019s data structure to find the concrete type an interface points to. But this isn\u2019t an issue in many contexts as the overhead is minimal.
In summary, we should be cautious when creating abstractions in our code\u2014abstractions should be discovered, not created. It\u2019s common for us, software developers, to overengineer our code by trying to guess what the perfect level of abstraction is, based on what we think we might need later. This process should be avoided because, in most cases, it pollutes our code with unnecessary abstractions, making it more complex to read.
Rob Pike
Don\u2019t design with interfaces, discover them.
Let\u2019s not try to solve a problem abstractly but solve what has to be solved now. Last, but not least, if it\u2019s unclear how an interface makes the code better, we should probably consider removing it to make our code simpler.
"},{"location":"56-concurrency-faster/","title":"Thinking concurrency is always faster","text":"A misconception among many developers is believing that a concurrent solution is always faster than a sequential one. This couldn\u2019t be more wrong. The overall performance of a solution depends on many factors, such as the efficiency of our code structure (concurrency), which parts can be tackled in parallel, and the level of contention among the computation units. This post reminds us about some fundamental knowledge of concurrency in Go; then we will see a concrete example where a concurrent solution isn\u2019t necessarily faster.
"},{"location":"56-concurrency-faster/#go-scheduling","title":"Go Scheduling","text":"A thread is the smallest unit of processing that an OS can perform. If a process wants to execute multiple actions simultaneously, it spins up multiple threads. These threads can be:
The OS is responsible for scheduling the thread\u2019s processes optimally so that:
The word thread can also have a different meaning at a CPU level. Each physical core can be composed of multiple logical cores (the concept of hyper-threading), and a logical core is also called a thread. In this post, when we use the word thread, we mean the unit of processing, not a logical core.
A CPU core executes different threads. When it switches from one thread to another, it executes an operation called context switching. The active thread consuming CPU cycles was in an executing state and moves to a runnable state, meaning it\u2019s ready to be executed pending an available core. Context switching is considered an expensive operation because the OS needs to save the current execution state of a thread before the switch (such as the current register values).
As Go developers, we can\u2019t create threads directly, but we can create goroutines, which can be thought of as application-level threads. However, whereas an OS thread is context-switched on and off a CPU core by the OS, a goroutine is context-switched on and off an OS thread by the Go runtime. Also, compared to an OS thread, a goroutine has a smaller memory footprint: 2 KB for goroutines from Go 1.4. An OS thread depends on the OS, but, for example, on Linux/x86\u201332, the default size is 2 MB (see https://man7.org/linux/man-pages/man3/pthread_create.3.html). Having a smaller size makes context switching faster.
NoteContext switching a goroutine versus a thread is about 80% to 90% faster, depending on the architecture.
Let\u2019s now discuss how the Go scheduler works to overview how goroutines are handled. Internally, the Go scheduler uses the following terminology (see proc.go):
Each OS thread (M) is assigned to a CPU core (P) by the OS scheduler. Then, each goroutine (G) runs on an M. The GOMAXPROCS variable defines the limit of Ms in charge of executing user-level code simultaneously. But if a thread is blocked in a system call (for example, I/O), the scheduler can spin up more Ms. As of Go 1.5, GOMAXPROCS is by default equal to the number of available CPU cores.
A goroutine has a simpler lifecycle than an OS thread. It can be doing one of the following:
There\u2019s one last stage to understand about the implementation of Go scheduling: when a goroutine is created but cannot be executed yet; for example, all the other Ms are already executing a G. In this scenario, what will the Go runtime do about it? The answer is queuing. The Go runtime handles two kinds of queues: one local queue per P and a global queue shared among all the Ps.
Figure 1 shows a given scheduling situation on a four-core machine with GOMAXPROCS equal to 4. The parts are the logical cores (Ps), goroutines (Gs), OS threads (Ms), local queues, and global queue:
Figure 1: An example of the current state of a Go application executed on a four-core machine. Goroutines that aren\u2019t in an executing state are either runnable (pending being executed) or waiting (pending a blocking operation)
First, we can see five Ms, whereas GOMAXPROCS is set to 4. But as we mentioned, if needed, the Go runtime can create more OS threads than the GOMAXPROCS value.
P0, P1, and P3 are currently busy executing Go runtime threads. But P2 is presently idle as M3 is switched off P2, and there\u2019s no goroutine to be executed. This isn\u2019t a good situation because six runnable goroutines are pending being executed, some in the global queue and some in other local queues. How will the Go runtime handle this situation? Here\u2019s the scheduling implementation in pseudocode (see proc.go):
runtime.schedule() {\n // Only 1/61 of the time, check the global runnable queue for a G.\n // If not found, check the local queue.\n // If not found,\n // Try to steal from other Ps.\n // If not, check the global runnable queue.\n // If not found, poll network.\n}\n
Every sixty-first execution, the Go scheduler will check whether goroutines from the global queue are available. If not, it will check its local queue. Meanwhile, if both the global and local queues are empty, the Go scheduler can pick up goroutines from other local queues. This principle in scheduling is called work stealing, and it allows an underutilized processor to actively look for another processor\u2019s goroutines and steal some.
One last important thing to mention: prior to Go 1.14, the scheduler was cooperative, which meant a goroutine could be context-switched off a thread only in specific blocking cases (for example, channel send or receive, I/O, waiting to acquire a mutex). Since Go 1.14, the Go scheduler is now preemptive: when a goroutine is running for a specific amount of time (10 ms), it will be marked preemptible and can be context-switched off to be replaced by another goroutine. This allows a long-running job to be forced to share CPU time.
Now that we understand the fundamentals of scheduling in Go, let\u2019s look at a concrete example: implementing a merge sort in a parallel manner.
"},{"location":"56-concurrency-faster/#parallel-merge-sort","title":"Parallel Merge Sort","text":"First, let\u2019s briefly review how the merge sort algorithm works. Then we will implement a parallel version. Note that the objective isn\u2019t to implement the most efficient version but to support a concrete example showing why concurrency isn\u2019t always faster.
The merge sort algorithm works by breaking a list repeatedly into two sublists until each sublist consists of a single element and then merging these sublists so that the result is a sorted list (see figure 2). Each split operation splits the list into two sublists, whereas the merge operation merges two sublists into a sorted list.
Figure 2: Applying the merge sort algorithm repeatedly breaks each list into two sublists. Then the algorithm uses a merge operation such that the resulting list is sorted
Here is the sequential implementation of this algorithm. We don\u2019t include all of the code as it\u2019s not the main point of this section:
func sequentialMergesort(s []int) {\n if len(s) <= 1 {\n return\n }\n\n middle := len(s) / 2\n sequentialMergesort(s[:middle]) // First half\n sequentialMergesort(s[middle:]) // Second half\n merge(s, middle) // Merges the two halves\n}\n\nfunc merge(s []int, middle int) {\n // ...\n}\n
This algorithm has a structure that makes it open to concurrency. Indeed, as each sequentialMergesort operation works on an independent set of data that doesn\u2019t need to be fully copied (here, an independent view of the underlying array using slicing), we could distribute this workload among the CPU cores by spinning up each sequentialMergesort operation in a different goroutine. Let\u2019s write a first parallel implementation:
func parallelMergesortV1(s []int) {\n if len(s) <= 1 {\n return\n }\n\n middle := len(s) / 2\n\n var wg sync.WaitGroup\n wg.Add(2)\n\n go func() { // Spins up the first half of the work in a goroutine\n defer wg.Done()\n parallelMergesortV1(s[:middle])\n }()\n\n go func() { // Spins up the second half of the work in a goroutine\n defer wg.Done()\n parallelMergesortV1(s[middle:])\n }()\n\n wg.Wait()\n merge(s, middle) // Merges the halves\n}\n
In this version, each half of the workload is handled in a separate goroutine. The parent goroutine waits for both parts by using sync.WaitGroup. Hence, we call the Wait method before the merge operation.
We now have a parallel version of the merge sort algorithm. Therefore, if we run a benchmark to compare this version against the sequential one, the parallel version should be faster, correct? Let\u2019s run it on a four-core machine with 10,000 elements:
Benchmark_sequentialMergesort-4 2278993555 ns/op\nBenchmark_parallelMergesortV1-4 17525998709 ns/op\n
Surprisingly, the parallel version is almost an order of magnitude slower. How can we explain this result? How is it possible that a parallel version that distributes a workload across four cores is slower than a sequential version running on a single machine? Let\u2019s analyze the problem.
If we have a slice of, say, 1,024 elements, the parent goroutine will spin up two goroutines, each in charge of handling a half consisting of 512 elements. Each of these goroutines will spin up two new goroutines in charge of handling 256 elements, then 128, and so on, until we spin up a goroutine to compute a single element.
If the workload that we want to parallelize is too small, meaning we\u2019re going to compute it too fast, the benefit of distributing a job across cores is destroyed: the time it takes to create a goroutine and have the scheduler execute it is much too high compared to directly merging a tiny number of items in the current goroutine. Although goroutines are lightweight and faster to start than threads, we can still face cases where a workload is too small.
So what can we conclude from this result? Does it mean the merge sort algorithm cannot be parallelized? Wait, not so fast.
Let\u2019s try another approach. Because merging a tiny number of elements within a new goroutine isn\u2019t efficient, let\u2019s define a threshold. This threshold will represent how many elements a half should contain in order to be handled in a parallel manner. If the number of elements in the half is fewer than this value, we will handle it sequentially. Here\u2019s a new version:
const max = 2048 // Defines the threshold\n\nfunc parallelMergesortV2(s []int) {\n if len(s) <= 1 {\n return\n }\n\n if len(s) <= max {\n sequentialMergesort(s) // Calls our initial sequential version\n } else { // If bigger than the threshold, keeps the parallel version\n middle := len(s) / 2\n\n var wg sync.WaitGroup\n wg.Add(2)\n\n go func() {\n defer wg.Done()\n parallelMergesortV2(s[:middle])\n }()\n\n go func() {\n defer wg.Done()\n parallelMergesortV2(s[middle:])\n }()\n\n wg.Wait()\n merge(s, middle)\n }\n}\n
If the number of elements in the s slice is smaller than max, we call the sequential version. Otherwise, we keep calling our parallel implementation. Does this approach impact the result? Yes, it does:
Benchmark_sequentialMergesort-4 2278993555 ns/op\nBenchmark_parallelMergesortV1-4 17525998709 ns/op\nBenchmark_parallelMergesortV2-4 1313010260 ns/op\n
Our v2 parallel implementation is more than 40% faster than the sequential one, thanks to this idea of defining a threshold to indicate when parallel should be more efficient than sequential.
NoteWhy did I set the threshold to 2,048? Because it was the optimal value for this specific workload on my machine. In general, such magic values should be defined carefully with benchmarks (running on an execution environment similar to production). It\u2019s also pretty interesting to note that running the same algorithm in a programming language that doesn\u2019t implement the concept of goroutines has an impact on the value. For example, running the same example in Java using threads means an optimal value closer to 8,192. This tends to illustrate how goroutines are more efficient than threads.
"},{"location":"56-concurrency-faster/#conclusion","title":"Conclusion","text":"We have seen throughout this post the fundamental concepts of scheduling in Go: the differences between a thread and a goroutine and how the Go runtime schedules goroutines. Meanwhile, using the parallel merge sort example, we illustrated that concurrency isn\u2019t always necessarily faster. As we have seen, spinning up goroutines to handle minimal workloads (merging only a small set of elements) demolishes the benefit we could get from parallelism.
So, where should we go from here? We must keep in mind that concurrency isn\u2019t always faster and shouldn\u2019t be considered the default way to go for all problems. First, it makes things more complex. Also, modern CPUs have become incredibly efficient at executing sequential code and predictable code. For example, a superscalar processor can parallelize instruction execution over a single core with high efficiency.
Does this mean we shouldn\u2019t use concurrency? Of course not. However, it\u2019s essential to keep these conclusions in mind. If we\u2019re not sure that a parallel version will be faster, the right approach may be to start with a simple sequential version and build from there using profiling (mistake #98, \u201cNot using Go diagnostics tooling\u201d) and benchmarks (mistake #89, \u201cWriting inaccurate benchmarks\u201d), for example. It can be the only way to ensure that a concurrent implementation is worth it.
"},{"location":"89-benchmarks/","title":"Writing inaccurate benchmarks","text":"In general, we should never guess about performance. When writing optimizations, so many factors may come into play that even if we have a strong opinion about the results, it\u2019s rarely a bad idea to test them. However, writing benchmarks isn\u2019t straightforward. It can be pretty simple to write inaccurate benchmarks and make wrong assumptions based on them. The goal of this post is to examine four common and concrete traps leading to inaccuracy:
Before discussing these traps, let\u2019s briefly review how benchmarks work in Go. The skeleton of a benchmark is as follows:
func BenchmarkFoo(b *testing.B) {\n for i := 0; i < b.N; i++ {\n foo()\n }\n}\n
The function name starts with the Benchmark
prefix. The function under test (foo) is called within the for
loop. b.N
represents a variable number of iterations. When running a benchmark, Go tries to make it match the requested benchmark time. The benchmark time is set by default to 1 second and can be changed with the -benchtime
flag. b.N
starts at 1; if the benchmark completes in under 1 second, b.N
is increased, and the benchmark runs again until b.N
roughly matches benchtime:
$ go test -bench=.\ncpu: Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz\nBenchmarkFoo-4 73 16511228 ns/op\n
Here, the benchmark took about 1 second, and foo
was executed 73 times, for an average execution time of 16,511,228 nanoseconds. We can change the benchmark time using -benchtime
:
$ go test -bench=. -benchtime=2s\nBenchmarkFoo-4 150 15832169 ns/op\n
foo
was executed roughly twice more than during the previous benchmark.
Next, let\u2019s look at some common traps.
"},{"location":"89-benchmarks/#not-resetting-or-pausing-the-timer","title":"Not resetting or pausing the timer","text":"In some cases, we need to perform operations before the benchmark loop. These operations may take quite a while (for example, generating a large slice of data) and may significantly impact the benchmark results:
func BenchmarkFoo(b *testing.B) {\n expensiveSetup()\n for i := 0; i < b.N; i++ {\n functionUnderTest()\n }\n}\n
In this case, we can use the ResetTimer
method before entering the loop:
func BenchmarkFoo(b *testing.B) {\n expensiveSetup()\n b.ResetTimer() // Reset the benchmark timer\n for i := 0; i < b.N; i++ {\n functionUnderTest()\n }\n}\n
Calling ResetTimer
zeroes the elapsed benchmark time and memory allocation counters since the beginning of the test. This way, an expensive setup can be discarded from the test results.
What if we have to perform an expensive setup not just once but within each loop iteration?
func BenchmarkFoo(b *testing.B) {\n for i := 0; i < b.N; i++ {\n expensiveSetup()\n functionUnderTest()\n }\n}\n
We can\u2019t reset the timer, because that would be executed during each loop iteration. But we can stop and resume the benchmark timer, surrounding the call to expensiveSetup
:
func BenchmarkFoo(b *testing.B) {\n for i := 0; i < b.N; i++ {\n b.StopTimer() // Pause the benchmark timer\n expensiveSetup()\n b.StartTimer() // Resume the benchmark timer\n functionUnderTest()\n }\n}\n
Here, we pause the benchmark timer to perform the expensive setup and then resume the timer.
NoteThere\u2019s one catch to remember about this approach: if the function under test is too fast to execute compared to the setup function, the benchmark may take too long to complete. The reason is that it would take much longer than 1 second to reach benchtime
. Calculating the benchmark time is based solely on the execution time of functionUnderTest
. So, if we wait a significant time in each loop iteration, the benchmark will be much slower than 1 second. If we want to keep the benchmark, one possible mitigation is to decrease benchtime
.
We must be sure to use the timer methods to preserve the accuracy of a benchmark.
"},{"location":"89-benchmarks/#making-wrong-assumptions-about-micro-benchmarks","title":"Making wrong assumptions about micro-benchmarks","text":"A micro-benchmark measures a tiny computation unit, and it can be extremely easy to make wrong assumptions about it. Let\u2019s say, for example, that we aren\u2019t sure whether to use atomic.StoreInt32
or atomic.StoreInt64
(assuming that the values we handle will always fit in 32 bits). We want to write a benchmark to compare both functions:
func BenchmarkAtomicStoreInt32(b *testing.B) {\n var v int32\n for i := 0; i < b.N; i++ {\n atomic.StoreInt32(&v, 1)\n }\n}\n\nfunc BenchmarkAtomicStoreInt64(b *testing.B) {\n var v int64\n for i := 0; i < b.N; i++ {\n atomic.StoreInt64(&v, 1)\n }\n}\n
If we run this benchmark, here\u2019s some example output:
cpu: Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz\nBenchmarkAtomicStoreInt32\nBenchmarkAtomicStoreInt32-4 197107742 5.682 ns/op\nBenchmarkAtomicStoreInt64\nBenchmarkAtomicStoreInt64-4 213917528 5.134 ns/op\n
We could easily take this benchmark for granted and decide to use atomic.StoreInt64
because it appears to be faster. Now, for the sake of doing a fair benchmark, we reverse the order and test atomic.StoreInt64
first, followed by atomic.StoreInt32
. Here is some example output:
BenchmarkAtomicStoreInt64\nBenchmarkAtomicStoreInt64-4 224900722 5.434 ns/op\nBenchmarkAtomicStoreInt32\nBenchmarkAtomicStoreInt32-4 230253900 5.159 ns/op\n
This time, atomic.StoreInt32
has better results. What happened?
In the case of micro-benchmarks, many factors can impact the results, such as machine activity while running the benchmarks, power management, thermal scaling, and better cache alignment of a sequence of instructions. We must remember that many factors, even outside the scope of our Go project, can impact the results.
NoteWe should make sure the machine executing the benchmark is idle. However, external processes may run in the background, which may affect benchmark results. For that reason, tools such as perflock
can limit how much CPU a benchmark can consume. For example, we can run a benchmark with 70% of the total available CPU, giving 30% to the OS and other processes and reducing the impact of the machine activity factor on the results.
One option is to increase the benchmark time using the -benchtime
option. Similar to the law of large numbers in probability theory, if we run a benchmark a large number of times, it should tend to approach its expected value (assuming we omit the benefits of instructions caching and similar mechanics).
Another option is to use external tools on top of the classic benchmark tooling. For instance, the benchstat
tool, which is part of the golang.org/x
repository, allows us to compute and compare statistics about benchmark executions.
Let\u2019s run the benchmark 10 times using the -count
option and pipe the output to a specific file:
$ go test -bench=. -count=10 | tee stats.txt\ncpu: Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz\nBenchmarkAtomicStoreInt32-4 234935682 5.124 ns/op\nBenchmarkAtomicStoreInt32-4 235307204 5.112 ns/op\n// ...\nBenchmarkAtomicStoreInt64-4 235548591 5.107 ns/op\nBenchmarkAtomicStoreInt64-4 235210292 5.090 ns/op\n// ...\n
We can then run benchstat
on this file:
$ benchstat stats.txt\nname time/op\nAtomicStoreInt32-4 5.10ns \u00b1 1%\nAtomicStoreInt64-4 5.10ns \u00b1 1%\n
The results are the same: both functions take on average 5.10 nanoseconds to complete. We also see the percent variation between the executions of a given benchmark: \u00b1 1%. This metric tells us that both benchmarks are stable, giving us more confidence in the computed average results. Therefore, instead of concluding that atomic.StoreInt32
is faster or slower, we can conclude that its execution time is similar to that of atomic.StoreInt64
for the usage we tested (in a specific Go version on a particular machine).
In general, we should be cautious about micro-benchmarks. Many factors can significantly impact the results and potentially lead to wrong assumptions. Increasing the benchmark time or repeating the benchmark executions and computing stats with tools such as benchstat
can be an efficient way to limit external factors and get more accurate results, leading to better conclusions.
Let\u2019s also highlight that we should be careful about using the results of a micro-benchmark executed on a given machine if another system ends up running the application. The production system may act quite differently from the one on which we ran the micro-benchmark.
"},{"location":"89-benchmarks/#not-being-careful-about-compiler-optimizations","title":"Not being careful about compiler optimizations","text":"Another common mistake related to writing benchmarks is being fooled by compiler optimizations, which can also lead to wrong benchmark assumptions. In this section, we look at Go issue 14813 (https://github.com/golang/go/issues/14813, also discussed by Go project member Dave Cheney) with a population count function (a function that counts the number of bits set to 1):
const m1 = 0x5555555555555555\nconst m2 = 0x3333333333333333\nconst m4 = 0x0f0f0f0f0f0f0f0f\nconst h01 = 0x0101010101010101\n\nfunc popcnt(x uint64) uint64 {\n x -= (x >> 1) & m1\n x = (x & m2) + ((x >> 2) & m2)\n x = (x + (x >> 4)) & m4\n return (x * h01) >> 56\n}\n
This function takes and returns a uint64
. To benchmark this function, we can write the following:
func BenchmarkPopcnt1(b *testing.B) {\n for i := 0; i < b.N; i++ {\n popcnt(uint64(i))\n }\n}\n
However, if we execute this benchmark, we get a surprisingly low result:
cpu: Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz\nBenchmarkPopcnt1-4 1000000000 0.2858 ns/op\n
A duration of 0.28 nanoseconds is roughly one clock cycle, so this number is unreasonably low. The problem is that the developer wasn\u2019t careful enough about compiler optimizations. In this case, the function under test is simple enough to be a candidate for inlining: an optimization that replaces a function call with the body of the called function and lets us prevent a function call, which has a small footprint. Once the function is inlined, the compiler notices that the call has no side effects and replaces it with the following benchmark:
func BenchmarkPopcnt1(b *testing.B) {\n for i := 0; i < b.N; i++ {\n // Empty\n }\n}\n
The benchmark is now empty \u2014 which is why we got a result close to one clock cycle. To prevent this from happening, a best practice is to follow this pattern:
In our case, we write the following benchmark:
var global uint64 // Define a global variable\n\nfunc BenchmarkPopcnt2(b *testing.B) {\n var v uint64 // Define a local variable\n for i := 0; i < b.N; i++ {\n v = popcnt(uint64(i)) // Assign the result to the local variable\n }\n global = v // Assign the result to the global variable\n}\n
global
is a global variable, whereas v is a local variable whose scope is the benchmark function. During each loop iteration, we assign the result of popcnt
to the local variable. Then we assign the latest result to the global variable.
Why not assign the result of the popcnt call directly to global to simplify the test? Writing to a global variable is slower than writing to a local variable (these concepts are discussed in 100 Go Mistakes, mistake #95: \u201cNot understanding stack vs. heap\u201d). Therefore, we should write each result to a local variable to limit the footprint during each loop iteration.
If we run these two benchmarks, we now get a significant difference in the results:
cpu: Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz\nBenchmarkPopcnt1-4 1000000000 0.2858 ns/op\nBenchmarkPopcnt2-4 606402058 1.993 ns/op\n
BenchmarkPopcnt2
is the accurate version of the benchmark. It guarantees that we avoid the inlining optimizations, which can artificially lower the execution time or even remove the call to the function under test. Relying on the results of BenchmarkPopcnt1
could have led to wrong assumptions.
Let\u2019s remember the pattern to avoid compiler optimizations fooling benchmark results: assign the result of the function under test to a local variable, and then assign the latest result to a global variable. This best practice also prevents us from making incorrect assumptions.
"},{"location":"89-benchmarks/#being-fooled-by-the-observer-effect","title":"Being fooled by the observer effect","text":"In physics, the observer effect is the disturbance of an observed system by the act of observation. This effect can also be seen in benchmarks and can lead to wrong assumptions about results. Let\u2019s look at a concrete example and then try to mitigate it.
We want to implement a function receiving a matrix of int64
elements. This matrix has a fixed number of 512 columns, and we want to compute the total sum of the first eight columns, as shown in figure 1.
Figure 1: Computing the sum of the first eight columns.
For the sake of optimizations, we also want to determine whether varying the number of columns has an impact, so we also implement a second function with 513 columns. The implementation is the following:
func calculateSum512(s [][512]int64) int64 {\n var sum int64\n for i := 0; i < len(s); i++ { // Iterate over each row\n for j := 0; j < 8; j++ { // Iterate over the first eight columns\n sum += s[i][j] // Increment sum\n }\n }\n return sum\n}\n\nfunc calculateSum513(s [][513]int64) int64 {\n // Same implementation as calculateSum512\n}\n
We iterate over each row and then over the first eight columns, and we increment a sum variable that we return. The implementation in calculateSum513
remains the same.
We want to benchmark these functions to decide which one is the most performant given a fixed number of rows:
const rows = 1000\n\nvar res int64\n\nfunc BenchmarkCalculateSum512(b *testing.B) {\n var sum int64\n s := createMatrix512(rows) // Create a matrix of 512 columns\n b.ResetTimer()\n for i := 0; i < b.N; i++ {\n sum = calculateSum512(s) // Create a matrix of 512 columns\n }\n res = sum\n}\n\nfunc BenchmarkCalculateSum513(b *testing.B) {\n var sum int64\n s := createMatrix513(rows) // Create a matrix of 513 columns\n b.ResetTimer()\n for i := 0; i < b.N; i++ {\n sum = calculateSum513(s) // Calculate the sum\n }\n res = sum\n}\n
We want to create the matrix only once, to limit the footprint on the results. Therefore, we call createMatrix512
and createMatrix513
outside of the loop. We may expect the results to be similar as again we only want to iterate on the first eight columns, but this isn\u2019t the case (on my machine):
cpu: Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz\nBenchmarkCalculateSum512-4 81854 15073 ns/op\nBenchmarkCalculateSum513-4 161479 7358 ns/op\n
The second benchmark with 513 columns is about 50% faster. Again, because we iterate only over the first eight columns, this result is quite surprising.
To understand this difference, we need to understand the basics of CPU caches. In a nutshell, a CPU is composed of different caches (usually L1, L2, and L3). These caches reduce the average cost of accessing data from the main memory. In some conditions, the CPU can fetch data from the main memory and copy it to L1. In this case, the CPU tries to fetch into L1 the matrix\u2019s subset that calculateSum
is interested in (the first eight columns of each row). However, the matrix fits in memory in one case (513 columns) but not in the other case (512 columns).
This isn\u2019t in the scope of this post to explain why, but we look at this problem in 100 Go Mistakes, mistake #91: \u201cNot understanding CPU caches.\u201d
Coming back to the benchmark, the main issue is that we keep reusing the same matrix in both cases. Because the function is repeated thousands of times, we don\u2019t measure the function\u2019s execution when it receives a plain new matrix. Instead, we measure a function that gets a matrix that already has a subset of the cells present in the cache. Therefore, because calculateSum513
leads to fewer cache misses, it has a better execution time.
This is an example of the observer effect. Because we keep observing a repeatedly called CPU-bound function, CPU caching may come into play and significantly affect the results. In this example, to prevent this effect, we should create a matrix during each test instead of reusing one:
func BenchmarkCalculateSum512(b *testing.B) {\n var sum int64\n for i := 0; i < b.N; i++ {\n b.StopTimer()\n s := createMatrix512(rows) // Create a new matrix during each loop iteration\n b.StartTimer()\n sum = calculateSum512(s)\n }\n res = sum\n}\n
A new matrix is now created during each loop iteration. If we run the benchmark again (and adjust benchtime
\u2014 otherwise, it takes too long to execute), the results are closer to each other:
cpu: Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz\nBenchmarkCalculateSum512-4 1116 33547 ns/op\nBenchmarkCalculateSum513-4 998 35507 ns/op\n
Instead of making the incorrect assumption that calculateSum513 is faster, we see that both benchmarks lead to similar results when receiving a new matrix.
As we have seen in this post, because we were reusing the same matrix, CPU caches significantly impacted the results. To prevent this, we had to create a new matrix during each loop iteration. In general, we should remember that observing a function under test may lead to significant differences in results, especially in the context of micro-benchmarks of CPU-bound functions where low-level optimizations matter. Forcing a benchmark to re-create data during each iteration can be a good way to prevent this effect.
"},{"location":"9-generics/","title":"Being confused about when to use generics","text":"Generics is a fresh addition to the language. In a nutshell, it allows writing code with types that can be specified later and instantiated when needed. However, it can be pretty easy to be confused about when to use generics and when not to. Throughout this post, we will describe the concept of generics in Go and then delve into common use and misuses.
"},{"location":"9-generics/#concepts","title":"Concepts","text":"Consider the following function that extracts all the keys from a map[string]int
type:
func getKeys(m map[string]int) []string {\n var keys []string\n for k := range m {\n keys = append(keys, k)\n }\n return keys\n}\n
What if we would like to use a similar feature for another map type such as a map[int]string
? Before generics, Go developers had a couple of options: using code generation, reflection, or duplicating code.
For example, we could write two functions, one for each map type, or even try to extend getKeys
to accept different map types:
func getKeys(m any) ([]any, error) {\n switch t := m.(type) {\n default:\n return nil, fmt.Errorf(\"unknown type: %T\", t)\n case map[string]int:\n var keys []any\n for k := range t {\n keys = append(keys, k)\n }\n return keys, nil\n case map[int]string:\n // Copy the extraction logic\n }\n}\n
We can start noticing a couple of issues:
range
loop.int
or string
, we are obliged to return a slice of empty interfaces to factor out key types. This approach increases the effort on the caller-side as the client may also have to perform a type check of the keys or extra conversion.Thanks to generics, we can now refactor this code using type parameters.
Type parameters are generic types we can use with functions and types. For example, the following function accepts a type parameter:
func foo[T any](t T) {\n // ...\n}\n
When calling foo
, we will pass a type argument of any type. Passing a type argument is called instantiation because the work is done at compile time which keeps type safety as part of the core language features and avoids runtime overheads.
Let\u2019s get back to the getKeys
function and use type parameters to write a generic version that would accept any kind of map:
func getKeys[K comparable, V any](m map[K]V) []K {\n var keys []K <2>\n for k := range m {\n keys = append(keys, k)\n }\n return keys\n}\n
To handle the map, we defined two kinds of type parameters. First, the values can be of any type: V any
. However, in Go, the map keys can\u2019t be of any type. For example, we cannot use slices:
var m map[[]byte]int\n
This code leads to a compilation error: invalid map key type []byte
. Therefore, instead of accepting any key type, we are obliged to restrict type arguments so that the key type meets specific requirements. Here, being comparable (we can use ==
or !=
). Hence, we defined K
as comparable
instead of any
.
Restricting type arguments to match specific requirements is called a constraint. A constraint is an interface type that can contain:
Let\u2019s see a concrete example for the latter. Imagine we don\u2019t want to accept any comparable
type for map key type. For instance, we would like to restrict it to either int
or string
types. We can define a custom constraint this way:
type customConstraint interface {\n ~int | ~string // Define a custom type that will restrict types to int and string\n}\n\n// Change the type parameter K to be custom\nfunc getKeys[K customConstraint, V any](m map[K]V) []K {\n // Same implementation\n}\n
First, we define a customConstraint
interface to restrict the types to be either int
or string
using the union operator |
(we will discuss the use of ~
a bit later). Then, K
is now a customConstraint
instead of a comparable
as before.
Now, the signature of getKeys
enforces that we can call it with a map of any value type, but the key type has to be an int
or a string
. For example, on the caller-side:
m = map[string]int{\n \"one\": 1,\n \"two\": 2,\n \"three\": 3,\n}\nkeys := getKeys(m)\n
Note that Go can infer that getKeys
is called with a string
type argument. The previous call was similar to this:
keys := getKeys[string](m)\n
Note What\u2019s the difference between a constraint using ~int
or int
? Using int
restricts it to that type, whereas ~int
restricts all the types whose underlying type is an int
.
To illustrate it, let\u2019s imagine a constraint where we would like to restrict a type to any int
type implementing the String() string
method:
type customConstraint interface {\n ~int\n String() string\n}\n
Using this constraint will restrict type arguments to custom types like this one:
type customInt int\n\nfunc (i customInt) String() string {\n return strconv.Itoa(int(i))\n}\n
As customInt
is an int
and implements the String() string
method, the customInt
type satisfies the constraint defined.
However, if we change the constraint to contain an int
instead of an ~int
, using customInt
would lead to a compilation error because the int
type doesn\u2019t implement String() string
.
Let\u2019s also note the constraints
package contains a set of common constraints such as Signed
that includes all the signed integer types. Let\u2019s ensure that a constraint doesn\u2019t already exist in this package before creating a new one.
So far, we have discussed examples using generics for functions. However, we can also use generics with data structures.
For example, we will create a linked list containing values of any type. Meanwhile, we will write an Add
method to append a node:
type Node[T any] struct { // Use type parameter\n Val T\n next *Node[T]\n}\n\nfunc (n *Node[T]) Add(next *Node[T]) { // Instantiate type receiver\n n.next = next\n}\n
We use type parameters to define T
and use both fields in Node
. Regarding the method, the receiver is instantiated. Indeed, because Node
is generic, it has to follow also the type parameter defined.
One last thing to note about type parameters: they can\u2019t be used on methods, only on functions. For example, the following method wouldn\u2019t compile:
type Foo struct {}\n\nfunc (Foo) bar[T any](t T) {}\n
./main.go:29:15: methods cannot have type parameters\n
Now, let\u2019s delve into concrete cases where we should and shouldn\u2019t use generics.
"},{"location":"9-generics/#common-uses-and-misuses","title":"Common uses and misuses","text":"So when are generics useful? Let\u2019s discuss a couple of common uses where generics are recommended:
func merge[T any](ch1, ch2 <-chan T) <-chan T {\n // ...\n}\n
sort
package contains functions to sort different slice types such as sort.Ints
or sort.Float64s
. Using type parameters, we can factor out the sorting behaviors that rely on three methods, Len
, Less
, and Swap
:type sliceFn[T any] struct { // Use type parameter\n s []T\n compare func(T, T) bool // Compare two T elements\n}\n\nfunc (s sliceFn[T]) Len() int { return len(s.s) }\nfunc (s sliceFn[T]) Less(i, j int) bool { return s.compare(s.s[i], s.s[j]) }\nfunc (s sliceFn[T]) Swap(i, j int) { s.s[i], s.s[j] = s.s[j], s.s[i] }\n
Conversely, when is it recommended not to use generics?
io.Writer
and call the Write
method:func foo[T io.Writer](w T) {\n b := getBytes()\n _, _ = w.Write(b)\n}\n
Though generics can be very helpful in particular conditions, we should be cautious about when to use them and not use them.
In general, when we want to answer when not to use generics, we can find similarities with when not to use interfaces. Indeed, generics introduce a form of abstraction, and we have to remember that unnecessary abstractions introduce complexity.
Let\u2019s not pollute our code with needless abstractions, and let\u2019s focus on solving concrete problems for now. It means that we shouldn\u2019t use type parameters prematurely. Let\u2019s wait until we are about to write boilerplate code to consider using generics.
"},{"location":"92-false-sharing/","title":"Writing concurrent code that leads to false sharing","text":"In previous sections, we have discussed the fundamental concepts of CPU caching. We have seen that some specific caches (typically, L1 and L2) aren\u2019t shared among all the logical cores but are specific to a physical core. This specificity has some concrete impacts such as concurrency and the concept of false sharing, which can lead to a significant performance decrease. Let\u2019s look at what false sharing is via an example and then see how to prevent it.
In this example, we use two structs, Input
and Result
:
type Input struct {\n a int64\n b int64\n}\n\ntype Result struct {\n sumA int64\n sumB int64\n}\n
The goal is to implement a count
function that receives a slice of Input
and computes the following:
Input.a
fields into Result.sumA
Input.b
fields into Result.sumB
For the sake of the example, we implement a concurrent solution with one goroutine that computes sumA
and another that computes sumB
:
func count(inputs []Input) Result {\n wg := sync.WaitGroup{}\n wg.Add(2)\n\n result := Result{} // Init the result struct\n\n go func() {\n for i := 0; i < len(inputs); i++ {\n result.sumA += inputs[i].a // Computes sumA\n }\n wg.Done()\n }()\n\n go func() {\n for i := 0; i < len(inputs); i++ {\n result.sumB += inputs[i].b // Computes sumB\n }\n wg.Done()\n }()\n\n wg.Wait()\n return result\n}\n
We spin up two goroutines: one that iterates over each a field and another that iterates over each b field. This example is fine from a concurrency perspective. For instance, it doesn\u2019t lead to a data race, because each goroutine increments its own variable. But this example illustrates the false sharing concept that degrades expected performance.
Let\u2019s look at the main memory. Because sumA
and sumB
are allocated contiguously, in most cases (seven out of eight), both variables are allocated to the same memory block:
In this example, sumA and sumB are part of the same memory block.
Now, let\u2019s assume that the machine contains two cores. In most cases, we should eventually have two threads scheduled on different cores. So if the CPU decides to copy this memory block to a cache line, it is copied twice:
Each block is copied to a cache line on both code 0 and core 1.
Both cache lines are replicated because L1D (L1 data) is per core. Recall that in our example, each goroutine updates its own variable: sumA
on one side, and sumB
on the other side:
Each goroutine updates its own variable.
Because these cache lines are replicated, one of the goals of the CPU is to guarantee cache coherency. For example, if one goroutine updates sumA
and another reads sumA
(after some synchronization), we expect our application to get the latest value.
However, our example doesn\u2019t do exactly this. Both goroutines access their own variables, not a shared one. We might expect the CPU to know about this and understand that it isn\u2019t a conflict, but this isn\u2019t the case. When we write a variable that\u2019s in a cache, the granularity tracked by the CPU isn\u2019t the variable: it\u2019s the cache line.
When a cache line is shared across multiple cores and at least one goroutine is a writer, the entire cache line is invalidated. This happens even if the updates are logically independent (for example, sumA
and sumB
). This is the problem of false sharing, and it degrades performance.
Internally, a CPU uses the MESI protocol to guarantee cache coherency. It tracks each cache line, marking it modified, exclusive, shared, or invalid (MESI).
One of the most important aspects to understand about memory and caching is that sharing memory across cores isn\u2019t real\u2014it\u2019s an illusion. This understanding comes from the fact that we don\u2019t consider a machine a black box; instead, we try to have mechanical sympathy with underlying levels.
So how do we solve false sharing? There are two main solutions.
The first solution is to use the same approach we\u2019ve shown but ensure that sumA
and sumB
aren\u2019t part of the same cache line. For example, we can update the Result
struct to add padding between the fields. Padding is a technique to allocate extra memory. Because an int64
requires an 8-byte allocation and a cache line 64 bytes long, we need 64 \u2013 8 = 56 bytes of padding:
type Result struct {\n sumA int64\n _ [56]byte // Padding\n sumB int64\n}\n
The next figure shows a possible memory allocation. Using padding, sumA
and sumB
will always be part of different memory blocks and hence different cache lines.
sumA and sumB are part of different memory blocks.
If we benchmark both solutions (with and without padding), we see that the padding solution is significantly faster (about 40% on my machine). This is an important improvement that results from the addition of padding between the two fields to prevent false sharing.
The second solution is to rework the structure of the algorithm. For example, instead of having both goroutines share the same struct, we can make them communicate their local result via channels. The result benchmark is roughly the same as with padding.
In summary, we must remember that sharing memory across goroutines is an illusion at the lowest memory levels. False sharing occurs when a cache line is shared across two cores when at least one goroutine is a writer. If we need to optimize an application that relies on concurrency, we should check whether false sharing applies, because this pattern is known to degrade application performance. We can prevent false sharing with either padding or communication.
"},{"location":"98-profiling-execution-tracing/","title":"Not using Go diagnostics tooling","text":"Go offers a few excellent diagnostics tools to help us get insights into how an application performs. This post focuses on the most important ones: profiling and the execution tracer. Both tools are so important that they should be part of the core toolset of any Go developer who is interested in optimization. First, let\u2019s discuss profiling.
"},{"location":"98-profiling-execution-tracing/#profiling","title":"Profiling","text":"Profiling provides insights into the execution of an application. It allows us to resolve performance issues, detect contention, locate memory leaks, and more. These insights can be collected via several profiles:
CPU
\u2014 Determines where an application spends its timeGoroutine
\u2014 Reports the stack traces of the ongoing goroutinesHeap
\u2014 Reports heap memory allocation to monitor current memory usage and check for possible memory leaksMutex
\u2014 Reports lock contentions to see the behaviors of the mutexes used in our code and whether an application spends too much time in locking callsBlock
\u2014 Shows where goroutines block waiting on synchronization primitivesProfiling is achieved via instrumentation using a tool called a profiler, in Go: pprof
. First, let\u2019s understand how and when to enable pprof
; then, we discuss the most critical profile types.
There are several ways to enable pprof
. For example, we can use the net/http/pprof
package to serve the profiling data via HTTP:
package main\n\nimport (\n \"fmt\"\n \"log\"\n \"net/http\"\n _ \"net/http/pprof\" // Blank import to pprof\n)\n\nfunc main() {\n // Exposes an HTTP endpoint\n http.HandleFunc(\"/\", func(w http.ResponseWriter, r *http.Request) {\n fmt.Fprintf(w, \"\")\n })\n log.Fatal(http.ListenAndServe(\":80\", nil))\n}\n
Importing net/http/pprof
leads to a side effect that allows us to reach the pprof URL: http://host/debug/pprof. Note that enabling pprof
is safe even in production (https://go.dev/doc/diagnostics#profiling). The profiles that impact performance, such as CPU profiling, aren\u2019t enabled by default, nor do they run continuously: they are activated only for a specific period.
Now that we have seen how to expose a pprof
endpoint, let\u2019s discuss the most common profiles.
The CPU profiler relies on the OS and signaling. When it is activated, the application asks the OS to interrupt it every 10 ms by default via a SIGPROF
signal. When the application receives a SIGPROF
, it suspends the current activity and transfers the execution to the profiler. The profiler collects data such as the current goroutine activity and aggregates execution statistics that we can retrieve. Then it stops, and the execution resumes until the next SIGPROF
.
We can access the /debug/pprof/profile endpoint to activate CPU profiling. Accessing this endpoint executes CPU profiling for 30 seconds by default. For 30 seconds, our application is interrupted every 10 ms. Note that we can change these two default values: we can use the seconds
parameter to pass to the endpoint how long the profiling should last (for example, /debug/pprof/profile?seconds=15), and we can change the interruption rate (even to less than 10 ms). But in most cases, 10 ms should be enough, and in decreasing this value (meaning increasing the rate), we should be careful not to harm performance. After 30 seconds, we download the results of the CPU profiler.
We can also enable the CPU profiler using the -cpuprofile
flag, such as when running a benchmark. For example, the following command produces the same type of file that can be downloaded via /debug/ pprof/profile.
$ go test -bench=. -cpuprofile profile.out\n
From this file, we can navigate to the results using go tool
:
$ go tool pprof -http=:8080 <file>\n
This command opens a web UI showing the call graph. The next figure shows an example taken from an application. The larger the arrow, the more it was a hot path. We can then navigate into this graph and get execution insights.
Figure 1: The call graph of an application during 30 seconds.
For example, the graph in the next figure tells us that during 30 seconds, 0.06 seconds were spent in the decode
method (*FetchResponse
receiver). Of these 0.06 seconds, 0.02 were spent in RecordBatch.decode
and 0.01 in makemap
(creating a map).
Figure 2: Example call graph.
We can also access this kind of information from the web UI with different representations. For example, the Top view sorts the functions per execution time, and Flame Graph visualizes the execution time hierarchy. The UI can even display the expensive parts of the source code line by line.
NoteWe can also delve into profiling data via a command line. However, we focus on the web UI in this post.
Thanks to this data, we can get a general idea of how an application behaves:
runtime.mallogc
can mean an excessive number of small heap allocations that we can try to minimize.syscall.Read
or syscall.Write
means the application spends a significant amount of time in Kernel mode. Working on I/O buffering may be an avenue for improvement.These are the kinds of insights we can get from the CPU profiler. It\u2019s valuable to understand the hottest code path and identify bottlenecks. But it won\u2019t determine more than the configured rate because the CPU profiler is executed at a fixed pace (by default, 10 ms). To get finer-grained insights, we should use tracing, which we discuss later in this post.
NoteWe can also attach labels to the different functions. For example, imagine a common function called from different clients. To track the time spent for both clients, we can use pprof.Labels
.
Heap profiling allows us to get statistics about the current heap usage. Like CPU profiling, heap profiling is sample-based. We can change this rate, but we shouldn\u2019t be too granular because the more we decrease the rate, the more effort heap profiling will require to collect data. By default, samples are profiled at one allocation for every 512 KB of heap allocation.
If we reach /debug/pprof/heap/, we get raw data that can be hard to read. However, we can download a heap profile using /debug/pprof/heap/?debug=0 and then open it with go tool
(the same command as in the previous section) to navigate into the data using the web UI.
The next figure shows an example of a heap graph. Calling the MetadataResponse.decode
method leads to allocating 1536 KB of heap data (which represents 6.32% of the total heap). However, 0 out of these 1536 KB were allocated by this function directly, so we need to inspect the second call. The TopicMetadata.decode
method allocated 512 KB out of the 1536 KB; the rest \u2014 1024 KB \u2014 were allocated in another method.
Figure 3: A heap graph.
This is how we can navigate the call chain to understand what part of an application is responsible for most of the heap allocations. We can also look at different sample types:
alloc_objects
\u2014 Total number of objects allocatedalloc_space
\u2014 Total amount of memory allocatedinuse_object
s \u2014 Number of objects allocated and not yet releasedinuse_space
\u2014 Amount of memory allocated and not yet releasedAnother very helpful capability with heap profiling is tracking memory leaks. With a GC-based language, the usual procedure is the following:
Forcing a GC before downloading data is a way to prevent false assumptions. For example, if we see a peak of retained objects without running a GC first, we cannot be sure whether it\u2019s a leak or objects that the next GC will collect.
Using pprof
, we can download a heap profile and force a GC in the meantime. The procedure in Go is the following:
$ go tool pprof -http=:8080 -diff_base <file2> <file1>\n
The next figure shows the kind of data we can access. For example, the amount of heap memory held by the newTopicProducer method (top left) has decreased (\u2013513 KB). In contrast, the amount held by updateMetadata (bottom right) has increased (+512 KB). Slow increases are normal. The second heap profile may have been calculated in the middle of a service call, for example. We can repeat this process or wait longer; the important part is to track steady increases in allocations of a specific object.
Figure 4: The differences between the two heap profiles. Note
Another type of profiling related to the heap is allocs
, which reports allocations. Heap profiling shows the current state of the heap memory. To get insights about past memory allocations since the application started, we can use allocations profiling. As discussed, because stack allocations are cheap, they aren\u2019t part of this profiling, which only focuses on the heap.
The goroutine
profile reports the stack trace of all the current goroutines in an application. We can download a file using /debug/pprof/goroutine/?debug=0 and use go tool again. The next figure shows the kind of information we can get.
Figure 5: Goroutine graph.
We can see the current state of the application and how many goroutines were created per function. In this case, withRecover
has created 296 ongoing goroutines (63%), and 29 were related to a call to responseFeeder
.
This kind of information is also beneficial if we suspect goroutine leaks. We can look at goroutine profiler data to know which part of a system is the suspect.
"},{"location":"98-profiling-execution-tracing/#block-profiling","title":"Block Profiling","text":"The block
profile reports where ongoing goroutines block waiting on synchronization primitives. Possibilities include
Block profiling also records the amount of time a goroutine has been waiting and is accessible via /debug/pprof/block. This profile can be extremely helpful if we suspect that performance is being harmed by blocking calls.
The block
profile isn\u2019t enabled by default: we have to call runtime.SetBlockProfileRate
to enable it. This function controls the fraction of goroutine blocking events that are reported. Once enabled, the profiler will keep collecting data in the background even if we don\u2019t call the /debug/pprof/block endpoint. Let\u2019s be cautious if we want to set a high rate so we don\u2019t harm performance.
If we face a deadlock or suspect that goroutines are in a blocked state, the full goroutine stack dump (/debug/pprof/goroutine/?debug=2) creates a dump of all the current goroutine stack traces. This can be helpful as a first analysis step. For example, the following dump shows a Sarama goroutine blocked for 1,420 minutes on a channel-receive operation:
goroutine 2494290 [chan receive, 1420 minutes]:\ngithub.com/Shopify/sarama.(*syncProducer).SendMessages(0xc00071a090,\n[CA]{0xc0009bb800, 0xfb, 0xfb})\n/app/vendor/github.com/Shopify/sarama/sync_producer.go:117 +0x149\n
"},{"location":"98-profiling-execution-tracing/#mutex-profiling","title":"Mutex Profiling","text":"The last profile type is related to blocking but only regarding mutexes. If we suspect that our application spends significant time waiting for locking mutexes, thus harming execution, we can use mutex profiling. It\u2019s accessible via /debug/pprof/mutex.
This profile works in a manner similar to that for blocking. It\u2019s disabled by default: we have to enable it using runtime.SetMutexProfileFraction
, which controls the fraction of mutex contention events reported.
Following are a few additional notes about profiling:
threadcreate
profile because it\u2019s been broken since 2013 (https://github.com/golang/go/issues/6104).pprof
is extensible, and we can create our own custom profiles using pprof.Profile
.We have seen the most important profiles that we can enable to help us understand how an application performs and possible avenues for optimization. In general, enabling pprof
is recommended, even in production, because in most cases it offers an excellent balance between its footprint and the amount of insight we can get from it. Some profiles, such as the CPU profile, lead to performance penalties but only during the time they are enabled.
Let\u2019s now look at the execution tracer.
"},{"location":"98-profiling-execution-tracing/#execution-tracer","title":"Execution Tracer","text":"The execution tracer is a tool that captures a wide range of runtime events with go tool
to make them available for visualization. It is helpful for the following:
Let\u2019s try it with an example given the Concurrency isn\u2019t Always Faster in Go section. We discussed two parallel versions of the merge sort algorithm. The issue with the first version was poor parallelization, leading to the creation of too many goroutines. Let\u2019s see how the tracer can help us in validating this statement.
We will write a benchmark for the first version and execute it with the -trace flag to enable the execution tracer:
$ go test -bench=. -v -trace=trace.out\n
Note We can also download a remote trace file using the /debug/pprof/ trace?debug=0 pprof endpoint.
This command creates a trace.out file that we can open using go tool:
$ go tool trace trace.out\n2021/11/26 21:36:03 Parsing trace...\n2021/11/26 21:36:31 Splitting trace...\n2021/11/26 21:37:00 Opening browser. Trace viewer is listening on\n http://127.0.0.1:54518\n
The web browser opens, and we can click View Trace to see all the traces during a specific timeframe, as shown in the next figure. This figure represents about 150 ms. We can see multiple helpful metrics, such as the goroutine count and the heap size. The heap size grows steadily until a GC is triggered. We can also observe the activity of the Go application per CPU core. The timeframe starts with user-level code; then a \u201cstop the world\u201d is executed, which occupies the four CPU cores for approximately 40 ms.
Figure 6: Showing goroutine activity and runtime events such as a GC phase.
Regarding concurrency, we can see that this version uses all the available CPU cores on the machine. However, the next figure zooms in on a portion of 1 ms. Each bar corresponds to a single goroutine execution. Having too many small bars doesn\u2019t look right: it means execution that is poorly parallelized.
Figure 7: Too many small bars mean poorly parallelized execution.
The next figure zooms even closer to see how these goroutines are orchestrated. Roughly 50% of the CPU time isn\u2019t spent executing application code. The white spaces represent the time the Go runtime takes to spin up and orchestrate new goroutines.
Figure 8: About 50% of CPU time is spent handling goroutine switches.
Let\u2019s compare this with the second parallel implementation, which was about an order of magnitude faster. The next figure again zooms to a 1 ms timeframe.
Figure 9: The number of white spaces has been significantly reduced, proving that the CPU is more fully occupied.
Each goroutine takes more time to execute, and the number of white spaces has been significantly reduced. Hence, the CPU is much more occupied executing application code than it was in the first version. Each millisecond of CPU time is spent more efficiently, explaining the benchmark differences.
Note that the granularity of the traces is per goroutine, not per function like CPU profiling. However, it\u2019s possible to define user-level tasks to get insights per function or group of functions using the runtime/trace
package.
For example, imagine a function that computes a Fibonacci number and then writes it to a global variable using atomic. We can define two different tasks:
var v int64\n// Creates a fibonacci task\nctx, fibTask := trace.NewTask(context.Background(), \"fibonacci\")\ntrace.WithRegion(ctx, \"main\", func() {\n v = fibonacci(10)\n})\nfibTask.End()\n\n// Creates a store task\nctx, fibStore := trace.NewTask(ctx, \"store\")\ntrace.WithRegion(ctx, \"main\", func() {\n atomic.StoreInt64(&result, v)\n})\nfibStore.End()\n
Using go tool
, we can get more precise information about how these two tasks perform. In the previous trace UI, we can see the boundaries for each task per goroutine. In User-Defined Tasks, we can follow the duration distribution:
Figure 10: Distribution of user-level tasks.
We see that in most cases, the fibonacci
task is executed in less than 15 microseconds, whereas the store
task takes less than 6309 nanoseconds.
In the previous section, we discussed the kinds of information we can get from CPU profiling. What are the main differences compared to the data we can get from user-level traces?
runtime/trace
package)In summary, the execution tracer is a powerful tool for understanding how an application performs. As we have seen with the merge sort example, we can identify poorly parallelized execution. However, the tracer\u2019s granularity remains per goroutine unless we manually use runtime/trace
compared to a CPU profile, for example. We can use both profiling and the execution tracer to get the most out of the standard Go diagnostics tools when optimizing an application.
If you're a Go developer looking to improve your skills, the 100 Go Mistakes and How to Avoid Them book is for you. With a focus on practical examples, this book covers a wide range of topics from concurrency and error handling to testing and code organization. You'll learn to write more idiomatic, efficient, and maintainable code and become a proficient Go developer.
Read a summary of the 100 mistakes or the first chapter.
"},{"location":"book/#quotes-and-ratings","title":"Quotes and Ratings","text":"Krystian (Goodreads user)
This is an exceptional book. Usually, if a book contains either high-quality explanations or is written succinctly, I consider myself lucky to have found it. This one combines these two characteristics, which is super rare. It's another Go book for me and I still had quite a lot of \"a-ha!\" moments while reading it, and all of that without the unnecessary fluff, just straight to the point.
Akash Chetty
The book is completely exceptional, especially the examples carved out for each topic are really great. There is one topic that I struggled to understand is Concurrency but the way it is explained in this book is truly an art of genius.
Neeraj Shah
This should be the required reading for all Golang developers before they touch code in Production... It's the Golang equivalent of the legendary 'Effective Java' by Joshua Bloch.
Anupam Sengupta
Not having this will be the 101st mistake a Go programmer could make.
Manning, Goodreads, and Amazon reviews: 4.7/5 avg rating"},{"location":"book/#where-to-buy","title":"Where to Buy?","text":"
100 Go Mistakes and How to Avoid Them (\ud83c\uddec\ud83c\udde7 edition: paper, digital, or audiobook)
au35har
)Go\u8a00\u8a9e100Tips \u958b\u767a\u8005\u306b\u3042\u308a\u304c\u3061\u306a\u9593\u9055\u3044\u3078\u306e\u5bfe\u51e6\u6cd5 (\ud83c\uddef\ud83c\uddf5 edition: paper or digital)
100\u4e2aGo\u8bed\u8a00\u5178\u578b\u9519\u8bef (\ud83c\udde8\ud83c\uddf3 edition: paper or digital)
Go 100\uac00\uc9c0 \uc2e4\uc218 \ud328\ud134\uacfc \uc194\ub8e8\uc158 (\ud83c\uddf0\ud83c\uddf7 edition: paper or digital)
Covers (English, Japanese, Chinese, and Korean)"},{"location":"book/#about-the-author","title":"About the Author","text":"
Teiva Harsanyi is a senior software engineer at Google. He has worked in various domains, including insurance, transportation, and safety-critical industries like air traffic management. He is passionate about Go and how to design and implement reliable systems.
"},{"location":"chapter-1/","title":"Go: Simple to learn but hard to master","text":"This chapter covers
Making mistakes is part of everyone\u2019s life. As Albert Einstein once said,
Albert Einstein
A person who never made a mistake never tried anything new.
What matters in the end isn\u2019t the number of mistakes we make, but our capacity to learn from them. This assertion also applies to programming. The seniority we acquire in a language isn\u2019t a magical process; it involves making many mistakes and learning from them. The purpose of this book is centered around this idea. It will help you, the reader, become a more proficient Go developer by looking at and learning from 100 common mistakes people make in many areas of the language.
This chapter presents a quick refresher as to why Go has become mainstream over the years. We\u2019ll discuss why, despite Go being considered simple to learn, mastering its nuances can be challenging. Finally, we\u2019ll introduce the concepts this book covers.
"},{"location":"chapter-1/#go-outline","title":"Go outline","text":"If you are reading this book, it\u2019s likely that you\u2019re already sold on Go. Therefore, this section provides a brief reminder about what makes Go such a powerful language.
Software engineering has evolved considerably during the past decades. Most modern systems are no longer written by a single person but by teams consisting of multiple programmers\u2014sometimes even hundreds, if not thousands. Nowadays, code must be readable, expressive, and maintainable to guarantee a system\u2019s durability over the years. Meanwhile, in our fast-moving world, maximizing agility and reducing the time to market is critical for most organizations. Programming should also follow this trend, and companies strive to ensure that software engineers are as productive as possible when reading, writing, and maintaining code.
In response to these challenges, Google created the Go programming language in 2007. Since then, many organizations have adopted the language to support various use cases: APIs, automation, databases, CLIs (command-line interfaces), and so on. Many today consider Go the language of the cloud.
Feature-wise, Go has no type inheritance, no exceptions, no macros, no partial functions, no support for lazy variable evaluation or immutability, no operator overloading, no pattern matching, and on and on. Why are these features missing from the language? The official Go FAQ gives us some insight:
Go FAQ
Why does Go not have feature X? Your favorite feature may be missing because it doesn\u2019t fit, because it affects compilation speed or clarity of design, or because it would make the fundamental system model too difficult.
Judging the quality of a programming language via its number of features is probably not an accurate metric. At least, it\u2019s not an objective of Go. Instead, Go utilizes a few essential characteristics when adopting a language at scale for an organization. These include the following:
Go was built from the ground up with solid features such as outstanding concurrency primitives with goroutines and channels. There\u2019s not a strong need to rely on external libraries to build efficient concurrent applications. Observing how important concurrency is these days also demonstrates why Go is such a suitable language for the present and probably for the foreseeable future.
Some also consider Go a simple language. And, in a sense, this isn\u2019t necessarily wrong. For example, a newcomer can learn the language\u2019s main features in less than a day. So why read a book centered on the concept of mistakes if Go is simple?
"},{"location":"chapter-1/#simple-doesnt-mean-easy","title":"Simple doesn\u2019t mean easy","text":"There is a subtle difference between simple and easy. Simple, applied to a technology, means not complicated to learn or understand. However, easy means that we can achieve anything without much effort. Go is simple to learn but not necessarily easy to master.
Let\u2019s take concurrency, for example. In 2019, a study focusing on concurrency bugs was published: Understanding Real-World Concurrency Bugs in Go. This study was the first systematic analysis of concurrency bugs. It focused on multiple popular Go repositories such as Docker, gRPC, and Kubernetes. One of the most important takeaways from this study is that most of the blocking bugs are caused by inaccurate use of the message-passing paradigm via channels, despite the belief that message passing is easier to handle and less error-prone than sharing memory.
What should be an appropriate reaction to such a takeaway? Should we consider that the language designers were wrong about message passing? Should we reconsider how we deal with concurrency in our project? Of course not.
It\u2019s not a question of confronting message passing versus sharing memory and determining the winner. However, it\u2019s up to us as Go developers to thoroughly understand how to use concurrency, its implications on modern processors, when to favor one approach over the other, and how to avoid common traps. This example highlights that although a concept such as channels and goroutines can be simple to learn, it isn\u2019t an easy topic in practice.
This leitmotif\u2014simple doesn\u2019t mean easy\u2014can be generalized to many aspects of Go, not only concurrency. Hence, to be proficient Go developers, we must have a thorough understanding of many aspects of the language, which requires time, effort, and mistakes.
This book aims to help accelerate our journey toward proficiency by delving into 100 Go mistakes.
"},{"location":"chapter-1/#100-go-mistakes","title":"100 Go mistakes","text":"Why should we read a book about common Go mistakes? Why not deepen our knowledge with an ordinary book that would dig into different topics?
In a 2011 article, neuroscientists proved that the best time for brain growth is when we\u2019re facing mistakes. 1 Haven\u2019t we all experienced the process of learning from a mistake and recalling that occasion after months or even years, when some context related to it? As presented in another article, by Janet Metcalfe, this happens because mistakes have a facilitative effect. 2 The main idea is that we can remember not only the error but also the context surrounding the mistake. This is one of the reasons why learning from mistakes is so efficient.
To strengthen this facilitative effect, this book accompanies each mistake as much as possible with real-world examples. This book isn\u2019t only about theory; it also helps us get better at avoiding mistakes and making more well-informed, conscious decisions because we now understand the rationale behind them.
Unknown
Tell me and I forget. Teach me and I remember. Involve me and I learn.
This book presents seven main categories of mistakes. Overall, the mistakes can be classified as
We introduce each mistake category next.
"},{"location":"chapter-1/#bugs","title":"Bugs","text":"The first type of mistake and probably the most obvious is software bugs. In 2020, a study conducted by Synopsys estimated the cost of software bugs in the U.S. alone to be over $2 trillion. 3
Furthermore, bugs can also lead to tragic impacts. We can, for example, mention cases such as Therac-25, a radiation therapy machine produced by Atomic Energy of Canada Limited (AECL). Because of a race condition, the machine gave its patients radiation doses that were hundreds of times greater than expected, leading to the death of three patients. Hence, software bugs aren\u2019t only about money. As developers, we should remember how impactful our jobs are.
This book covers plenty of cases that could lead to various software bugs, including data races, leaks, logic errors, and other defects. Although accurate tests should be a way to discover such bugs as early as possible, we may sometimes miss cases because of different factors such as time constraints or complexity. Therefore, as a Go developer, it\u2019s essential to make sure we avoid common bugs.
"},{"location":"chapter-1/#needless-complexity","title":"Needless complexity","text":"The next category of mistakes is related to unnecessary complexity. A significant part of software complexity comes from the fact that, as developers, we strive to think about imaginary futures. Instead of solving concrete problems right now, it can be tempting to build evolutionary software that could tackle whatever future use case arises. However, this leads to more drawbacks than benefits in most cases because it can make a codebase more complex to understand and reason about.
Getting back to Go, we can think of plenty of use cases where developers might be tempted to design abstractions for future needs, such as interfaces or generics. This book discusses topics where we should remain careful not to harm a codebase with needless complexity.
"},{"location":"chapter-1/#weaker-readability","title":"Weaker readability","text":"Another kind of mistake is to weaken readability. As Robert C. Martin wrote in his book Clean Code: A Handbook of Agile Software Craftsmanship, the ratio of time spent reading versus writing is well over 10 to 1. Most of us started to program on solo projects where readability wasn\u2019t that important. However, today\u2019s software engineering is programming with a time dimension: making sure we can still work with and maintain an application months, years, or perhaps even decades later.
When programming in Go, we can make many mistakes that can harm readability. These mistakes may include nested code, data type representations, or not using named result parameters in some cases. Throughout this book, we will learn how to write readable code and care for future readers (including our future selves).
"},{"location":"chapter-1/#suboptimal-or-unidiomatic-organization","title":"Suboptimal or unidiomatic organization","text":"Be it while working on a new project or because we acquire inaccurate reflexes, another type of mistake is organizing our code and a project suboptimally and unidiomatically. Such issues can make a project harder to reason about and maintain. This book covers some of these common mistakes in Go. For example, we\u2019ll look at how to structure a project and deal with utility packages or init functions. All in all, looking at these mistakes should help us organize our code and projects more efficiently and idiomatically.
"},{"location":"chapter-1/#lack-of-api-convenience","title":"Lack of API convenience","text":"Making common mistakes that weaken how convenient an API is for our clients is another type of mistake. If an API isn\u2019t user-friendly, it will be less expressive and, hence, harder to understand and more error-prone.
We can think about many situations such as overusing any types, using the wrong creational pattern to deal with options, or blindly applying standard practices from object-oriented programming that affect the usability of our APIs. This book covers common mistakes that prevent us from exposing convenient APIs for our users.
"},{"location":"chapter-1/#under-optimized-code","title":"Under-optimized code","text":"Under-optimized code is another type of mistake made by developers. It can happen for various reasons, such as not understanding language features or even a lack of fundamental knowledge. Performance is one of the most obvious impacts of this mistake, but not the only one.
We can think about optimizing code for other goals, such as accuracy. For example, this book provides some common techniques to ensure that floating-point operations are accurate. Meanwhile, we will cover plenty of cases that can negatively impact performance code because of poorly parallelized executions, not knowing how to reduce allocations, or the impacts of data alignment, for example. We will tackle optimization via different prisms.
"},{"location":"chapter-1/#lack-of-productivity","title":"Lack of productivity","text":"In most cases, what\u2019s the best language we can choose when working on a new project? The one we\u2019re the most productive with. Being comfortable with how a language works and exploiting it to get the best out of it is crucial to reach proficiency.
In this book, we will cover many cases and concrete examples that will help us to be more productive while working in Go. For instance, we\u2019ll look at writing efficient tests to ensure that our code works, relying on the standard library to be more effective, and getting the best out of the profiling tools and linters. Now, it\u2019s time to delve into those 100 common Go mistakes.
"},{"location":"chapter-1/#summary","title":"Summary","text":"J. S. Moser, H. S. Schroder, et al., \u201cMind Your Errors: Evidence for a Neural Mechanism Linking Growth Mindset to Adaptive Posterror Adjustments,\u201d Psychological Science, vol. 22, no. 12, pp. 1484\u20131489, Dec. 2011.\u00a0\u21a9
J. Metcalfe, \u201cLearning from Errors,\u201d Annual Review of Psychology, vol. 68, pp. 465\u2013489, Jan. 2017.\u00a0\u21a9
Synopsys, \u201cThe Cost of Poor Software Quality in the US: A 2020 Report.\u201d 2020. https://news.synopsys.com/2021-01-06-Synopsys-Sponsored-CISQ-Research-Estimates-Cost-of-Poor-Software-Quality-in-the-US-2-08-Trillion-in-2020.\u00a0\u21a9
Post
"},{"location":"external/#the-most-useful-book-for-a-go-programmer","title":"The Most Useful Book for a Go Programmer?","text":""},{"location":"external/#how-to-make-mistakes-in-go-go-time-190","title":"How to make mistakes in Go - Go Time #190","text":"Post
"},{"location":"external/#what-can-be-summarized-from-100-go-mistakes","title":"What can be summarized from 100 Go Mistakes?","text":"Post
"},{"location":"external/#book-review-100-go-mistakes-and-how-to-avoid-them_1","title":"Book review: 100 Go Mistakes and How to Avoid Them","text":"Post
"},{"location":"external/#chinese","title":"Chinese","text":""},{"location":"external/#100-go-mistakes-and-how-to-avoid-them","title":"\u6df1\u5ea6\u9605\u8bfb\u4e4b\u300a100 Go Mistakes and How to Avoid Them","text":"Post
"},{"location":"external/#100-go-mistakes","title":"100 Go Mistakes \u968f\u8bb0","text":"Post
"},{"location":"external/#go","title":"\u6211\u4e3a\u4ec0\u4e48\u653e\u5f03Go\u8bed\u8a00\uff1f","text":"Post
"},{"location":"external/#japanese","title":"Japanese","text":""},{"location":"external/#go100-go-mistakes-and-how-to-avoid-them","title":"\u6700\u8fd1\u8aad\u3093\u3060Go\u8a00\u8a9e\u306e\u672c\u306e\u7d39\u4ecb\uff1a100 Go Mistakes and How to Avoid Them","text":"Post
"},{"location":"external/#100-go-mistakes-and-how-to-avoid-them_1","title":"\u300e100 Go Mistakes and How to Avoid Them\u300f\u3092\u8aad\u3080","text":"Post
"},{"location":"external/#portuguese","title":"Portuguese","text":""},{"location":"external/#um-otimo-livro-para-programadores-go","title":"Um \u00d3TIMO livro para programadores Go","text":""},{"location":"ja/","title":"Go\u8a00\u8a9e\u3067\u3042\u308a\u304c\u3061\u306a\u9593\u9055\u3044","text":"\u3053\u306e\u30da\u30fc\u30b8\u306f\u300e100 Go Mistakes\u300f\u306e\u5185\u5bb9\u3092\u307e\u3068\u3081\u305f\u3082\u306e\u3067\u3059\u3002\u4e00\u65b9\u3067\u3001\u30b3\u30df\u30e5\u30cb\u30c6\u30a3\u306b\u958b\u304b\u308c\u305f\u30da\u30fc\u30b8\u3067\u3082\u3042\u308a\u307e\u3059\u3002\u300c\u3042\u308a\u304c\u3061\u306a\u9593\u9055\u3044\u300d\u304c\u65b0\u305f\u306b\u8ffd\u52a0\u3055\u308c\u308b\u3079\u304d\u3060\u3068\u304a\u8003\u3048\u3067\u3057\u305f\u3089 community mistake issue \u3092\u4f5c\u6210\u3057\u3066\u304f\u3060\u3055\u3044\u3002
JobsIs your company hiring? Sponsor the Japanese version of this repository and let a significant audience of Go developers (~1k unique visitors per week) know about your opportunities in this section.
\u6ce8\u610f\u73fe\u5728\u3001\u5927\u5e45\u306b\u591a\u304f\u306e\u30b3\u30f3\u30c6\u30f3\u30c4\u3092\u8ffd\u52a0\u3057\u3066\u5f37\u5316\u3057\u3066\u3044\u308b\u65b0\u3057\u3044\u30d0\u30fc\u30b8\u30e7\u30f3\u3092\u95b2\u89a7\u3057\u3066\u3044\u307e\u3059\u3002\u3053\u306e\u30d0\u30fc\u30b8\u30e7\u30f3\u306f\u307e\u3060\u958b\u767a\u4e2d\u3067\u3059\u3002\u554f\u984c\u3092\u898b\u3064\u3051\u305f\u5834\u5408\u306f\u3069\u3046\u305e\u6c17\u8efd\u306bPR\u3092\u4f5c\u6210\u3057\u3066\u304f\u3060\u3055\u3044\u3002
"},{"location":"ja/#_1","title":"\u30b3\u30fc\u30c9\u3068\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u69cb\u6210","text":""},{"location":"ja/#1","title":"\u610f\u56f3\u7684\u3067\u306a\u3044\u5909\u6570\u306e\u30b7\u30e3\u30c9\u30fc\u30a4\u30f3\u30b0 (#1)","text":"\u8981\u7d04\u5909\u6570\u306e\u30b7\u30e3\u30c9\u30fc\u30a4\u30f3\u30b0\u3092\u907f\u3051\u308b\u3053\u3068\u306f\u3001\u8aa4\u3063\u305f\u5909\u6570\u306e\u53c2\u7167\u3084\u8aad\u307f\u624b\u306e\u6df7\u4e71\u3092\u9632\u304e\u307e\u3059\u3002
\u5909\u6570\u306e\u30b7\u30e3\u30c9\u30fc\u30a4\u30f3\u30b0\u306f\u3001\u5909\u6570\u540d\u304c\u30d6\u30ed\u30c3\u30af\u5185\u3067\u518d\u5ba3\u8a00\u3055\u308c\u308b\u3053\u3068\u3067\u751f\u3058\u307e\u3059\u304c\u3001\u3053\u308c\u306f\u9593\u9055\u3044\u3092\u5f15\u304d\u8d77\u3053\u3057\u3084\u3059\u304f\u3057\u307e\u3059\u3002\u5909\u6570\u306e\u30b7\u30e3\u30c9\u30fc\u30a4\u30f3\u30b0\u3092\u7981\u6b62\u3059\u308b\u304b\u3069\u3046\u304b\u306f\u500b\u4eba\u306e\u597d\u307f\u306b\u3088\u308a\u307e\u3059\u3002\u305f\u3068\u3048\u3070\u3001\u30a8\u30e9\u30fc\u306b\u5bfe\u3057\u3066 err
\u306e\u3088\u3046\u306a\u65e2\u5b58\u306e\u5909\u6570\u540d\u3092\u518d\u5229\u7528\u3059\u308b\u3068\u4fbf\u5229\u306a\u5834\u5408\u304c\u3042\u308a\u307e\u3059\u3002\u3068\u306f\u3044\u3048\u3001\u30b3\u30fc\u30c9\u306f\u30b3\u30f3\u30d1\u30a4\u30eb\u3055\u308c\u305f\u3082\u306e\u306e\u3001\u5024\u3092\u53d7\u3051\u53d6\u3063\u305f\u5909\u6570\u304c\u4e88\u671f\u3057\u305f\u3082\u306e\u3067\u306f\u306a\u3044\u3068\u3044\u3046\u30b7\u30ca\u30ea\u30aa\u306b\u76f4\u9762\u3059\u308b\u53ef\u80fd\u6027\u304c\u3042\u308b\u305f\u3081\u3001\u539f\u5247\u3068\u3057\u3066\u5f15\u304d\u7d9a\u304d\u6ce8\u610f\u3092\u6255\u3046\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#2","title":"\u4e0d\u5fc5\u8981\u306b\u30cd\u30b9\u30c8\u3055\u308c\u305f\u30b3\u30fc\u30c9 (#2)","text":"\u8981\u7d04\u30cd\u30b9\u30c8\u304c\u6df1\u304f\u306a\u3089\u306a\u3044\u3088\u3046\u306b\u3057\u3001\u30cf\u30c3\u30d4\u30fc\u30d1\u30b9\u3092\u5de6\u5074\u306b\u63c3\u3048\u308b\u3053\u3068\u3067\u30e1\u30f3\u30bf\u30eb\u30b3\u30fc\u30c9\u30e2\u30c7\u30eb\u3092\u69cb\u7bc9\u3059\u308b\u3053\u3068\u304c\u5bb9\u6613\u306b\u306a\u308a\u307e\u3059\u3002
\u4e00\u822c\u7684\u306b\u3001\u95a2\u6570\u304c\u3088\u308a\u6df1\u3044\u30cd\u30b9\u30c8\u3092\u8981\u6c42\u3059\u308b\u307b\u3069\u3001\u8aad\u3093\u3067\u7406\u89e3\u3059\u308b\u3053\u3068\u304c\u3088\u308a\u8907\u96d1\u306b\u306a\u308a\u307e\u3059\u3002\u79c1\u305f\u3061\u306e\u30b3\u30fc\u30c9\u306e\u53ef\u8aad\u6027\u3092\u6700\u9069\u5316\u3059\u308b\u305f\u3081\u306b\u3001\u3053\u306e\u30eb\u30fc\u30eb\u306e\u9069\u7528\u65b9\u6cd5\u3092\u898b\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u3002
if
\u30d6\u30ed\u30c3\u30af\u304c\u8fd4\u3055\u308c\u308b\u3068\u304d\u3001\u3059\u3079\u3066\u306e\u5834\u5408\u306b\u304a\u3044\u3066 else
\u30d6\u30ed\u30c3\u30af\u3092\u7701\u7565\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002 \u305f\u3068\u3048\u3070\u3001\u6b21\u306e\u3088\u3046\u306b\u66f8\u304f\u3079\u304d\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u3002if foo() {\n // ...\n return true\n} else {\n // ...\n}\n
\u4ee3\u308f\u308a\u306b\u3001\u6b21\u306e\u3088\u3046\u306b else
\u30d6\u30ed\u30c3\u30af\u3092\u7701\u7565\u3057\u307e\u3059\u3002
if foo() {\n // ...\n return true\n}\n// ...\n
if s != \"\" {\n // ...\n} else {\n return errors.New(\"empty string\")\n}\n
\u3053\u3053\u3067\u306f\u3001\u7a7a\u306e s
\u304c\u30ce\u30f3\u30cf\u30c3\u30d4\u30fc\u30d1\u30b9\u3092\u8868\u3057\u307e\u3059\u3002\u3057\u305f\u304c\u3063\u3066\u3001\u6b21\u306e\u3088\u3046\u306b\u6761\u4ef6\u3092\u3072\u3063\u304f\u308a\u8fd4\u3059\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002
if s == \"\" {\n return errors.New(\"empty string\")\n}\n// ...\n
\u8aad\u307f\u3084\u3059\u3044\u30b3\u30fc\u30c9\u3092\u66f8\u304f\u3053\u3068\u306f\u3001\u3059\u3079\u3066\u306e\u958b\u767a\u8005\u306b\u3068\u3063\u3066\u91cd\u8981\u306a\u8ab2\u984c\u3067\u3059\u3002\u30cd\u30b9\u30c8\u3055\u308c\u305f\u30d6\u30ed\u30c3\u30af\u306e\u6570\u3092\u6e1b\u3089\u3059\u3088\u3046\u52aa\u3081\u3001\u30cf\u30c3\u30d4\u30fc\u30d1\u30b9\u3092\u5de6\u5074\u306b\u63c3\u3048\u3001\u3067\u304d\u308b\u3060\u3051\u65e9\u304f\u623b\u308b\u3053\u3068\u304c\u3001\u30b3\u30fc\u30c9\u306e\u53ef\u8aad\u6027\u3092\u5411\u4e0a\u3055\u305b\u308b\u5177\u4f53\u7684\u306a\u624b\u6bb5\u3067\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#init-3","title":"init\u95a2\u6570\u306e\u8aa4\u7528 (#3)","text":"\u8981\u7d04\u5909\u6570\u3092\u521d\u671f\u5316\u3059\u308b\u3068\u304d\u306f\u3001init\u95a2\u6570\u306e\u30a8\u30e9\u30fc\u51e6\u7406\u304c\u5236\u9650\u3055\u308c\u3066\u304a\u308a\u3001\u30b9\u30c6\u30fc\u30c8\u306e\u51e6\u7406\u3068\u30c6\u30b9\u30c8\u304c\u3088\u308a\u8907\u96d1\u306b\u306a\u308b\u3053\u3068\u306b\u6ce8\u610f\u3057\u3066\u304f\u3060\u3055\u3044\u3002\u307b\u3068\u3093\u3069\u306e\u5834\u5408\u3001\u521d\u671f\u5316\u306f\u7279\u5b9a\u306e\u95a2\u6570\u3068\u3057\u3066\u51e6\u7406\u3055\u308c\u308b\u3079\u304d\u3067\u3059\u3002
init\u95a2\u6570\u306f\u3001\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u30b9\u30c6\u30fc\u30c8\u3092\u521d\u671f\u5316\u3059\u308b\u305f\u3081\u306b\u4f7f\u7528\u3055\u308c\u308b\u95a2\u6570\u3067\u3059\u3002\u5f15\u6570\u3092\u53d6\u3089\u305a\u3001\u7d50\u679c\u3082\u8fd4\u3057\u307e\u305b\u3093\uff08 func()
\u95a2\u6570\uff09\u3002\u30d1\u30c3\u30b1\u30fc\u30b8\u304c\u521d\u671f\u5316\u3055\u308c\u308b\u3068\u3001\u30d1\u30c3\u30b1\u30fc\u30b8\u5185\u306e\u3059\u3079\u3066\u306e\u5b9a\u6570\u304a\u3088\u3073\u5909\u6570\u306e\u5ba3\u8a00\u304c\u8a55\u4fa1\u3055\u308c\u307e\u3059\u3002\u6b21\u306b\u3001init\u95a2\u6570\u304c\u5b9f\u884c\u3055\u308c\u307e\u3059\u3002
init\u95a2\u6570\u306f\u3044\u304f\u3064\u304b\u306e\u554f\u984c\u3092\u5f15\u304d\u8d77\u3053\u3059\u53ef\u80fd\u6027\u304c\u3042\u308a\u307e\u3059\u3002
init\u95a2\u6570\u306b\u306f\u6ce8\u610f\u304c\u5fc5\u8981\u3067\u3059\u3002\u305f\u3060\u3057\u3001\u9759\u7684\u69cb\u6210\u306e\u5b9a\u7fa9\u306a\u3069\u3001\u72b6\u6cc1\u306b\u3088\u3063\u3066\u306f\u5f79\u7acb\u3064\u5834\u5408\u304c\u3042\u308a\u307e\u3059\u3002\u305d\u308c\u4ee5\u5916\u306e\u307b\u3068\u3093\u3069\u306e\u5834\u5408\u3001\u521d\u671f\u5316\u51e6\u7406\u306f\u7279\u5b9a\u306e\u95a2\u6570\u3092\u901a\u3058\u3066\u884c\u308f\u308c\u308b\u3079\u304d\u3067\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#4","title":"\u30b2\u30c3\u30bf\u30fc\u3068\u30bb\u30c3\u30bf\u30fc\u306e\u4e71\u7528 (#4)","text":"\u8981\u7d04Go\u8a00\u8a9e\u3067\u306f\u3001\u6163\u7528\u7684\u306b\u30b2\u30c3\u30bf\u30fc\u3068\u30bb\u30c3\u30bf\u30fc\u306e\u4f7f\u7528\u3092\u5f37\u5236\u3059\u308b\u3053\u3068\u306f\u3042\u308a\u307e\u305b\u3093\u3002\u5b9f\u5229\u3092\u91cd\u8996\u3057\u3001\u52b9\u7387\u6027\u3068\u7279\u5b9a\u306e\u6163\u7fd2\u306b\u5f93\u3046\u3053\u3068\u3068\u306e\u9593\u306e\u9069\u5207\u306a\u30d0\u30e9\u30f3\u30b9\u3092\u898b\u3064\u3051\u308b\u3053\u3068\u304c\u3001\u9032\u3080\u3079\u304d\u9053\u3067\u3042\u308b\u306f\u305a\u3067\u3059\u3002
\u30c7\u30fc\u30bf\u306e\u30ab\u30d7\u30bb\u30eb\u5316\u3068\u306f\u3001\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u5024\u307e\u305f\u306f\u72b6\u614b\u3092\u96a0\u3059\u3053\u3068\u3092\u6307\u3057\u307e\u3059\u3002\u30b2\u30c3\u30bf\u30fc\u3068\u30bb\u30c3\u30bf\u30fc\u306f\u3001\u30a8\u30af\u30b9\u30dd\u30fc\u30c8\u3055\u308c\u3066\u3044\u306a\u3044\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u30d5\u30a3\u30fc\u30eb\u30c9\u306e\u4e0a\u306b\u30a8\u30af\u30b9\u30dd\u30fc\u30c8\u3055\u308c\u305f\u30e1\u30bd\u30c3\u30c9\u3092\u63d0\u4f9b\u3059\u308b\u3053\u3068\u3067\u30ab\u30d7\u30bb\u30eb\u5316\u3092\u53ef\u80fd\u306b\u3059\u308b\u624b\u6bb5\u3067\u3059\u3002
Go\u8a00\u8a9e\u3067\u306f\u3001\u4e00\u90e8\u306e\u8a00\u8a9e\u3067\u898b\u3089\u308c\u308b\u3088\u3046\u306a\u30b2\u30c3\u30bf\u30fc\u3068\u30bb\u30c3\u30bf\u30fc\u306e\u81ea\u52d5\u30b5\u30dd\u30fc\u30c8\u306f\u3042\u308a\u307e\u305b\u3093\u3002\u307e\u305f\u3001\u30b2\u30c3\u30bf\u30fc\u3068\u30bb\u30c3\u30bf\u30fc\u3092\u4f7f\u7528\u3057\u3066\u69cb\u9020\u4f53\u30d5\u30a3\u30fc\u30eb\u30c9\u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b\u3053\u3068\u306f\u5fc5\u9808\u3067\u3082\u6163\u7528\u7684\u3067\u3082\u3042\u308a\u307e\u305b\u3093\u3002\u5024\u3092\u3082\u305f\u3089\u3055\u306a\u3044\u69cb\u9020\u4f53\u306e\u30b2\u30c3\u30bf\u30fc\u3068\u30bb\u30c3\u30bf\u30fc\u3067\u30b3\u30fc\u30c9\u3092\u57cb\u3081\u308b\u3079\u304d\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u3002\u5b9f\u5229\u3092\u91cd\u8996\u3057\u3001\u4ed6\u306e\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u30d1\u30e9\u30c0\u30a4\u30e0\u3067\u6642\u306b\u306f\u8b70\u8ad6\u306e\u4f59\u5730\u304c\u306a\u3044\u3068\u8003\u3048\u3089\u308c\u3066\u3044\u308b\u6163\u7fd2\u306b\u5f93\u3046\u3053\u3068\u3068\u3001\u52b9\u7387\u6027\u3068\u306e\u9593\u306e\u9069\u5207\u306a\u30d0\u30e9\u30f3\u30b9\u3092\u898b\u3064\u3051\u308b\u3088\u3046\u52aa\u3081\u308b\u3079\u304d\u3067\u3059\u3002
Go\u8a00\u8a9e\u306f\u3001\u30b7\u30f3\u30d7\u30eb\u3055\u3092\u542b\u3080\u591a\u304f\u306e\u7279\u6027\u3092\u8003\u616e\u3057\u3066\u8a2d\u8a08\u3055\u308c\u305f\u72ec\u81ea\u306e\u8a00\u8a9e\u3067\u3042\u308b\u3053\u3068\u3092\u5fd8\u308c\u306a\u3044\u3067\u304f\u3060\u3055\u3044\u3002\u305f\u3060\u3057\u3001\u30b2\u30c3\u30bf\u30fc\u3068\u30bb\u30c3\u30bf\u30fc\u306e\u5fc5\u8981\u6027\u304c\u898b\u3064\u304b\u3063\u305f\u5834\u5408\u3001\u307e\u305f\u306f\u524d\u8ff0\u306e\u3088\u3046\u306b\u3001\u524d\u65b9\u4e92\u63db\u6027\u3092\u4fdd\u8a3c\u3057\u306a\u304c\u3089\u5c06\u6765\u306e\u5fc5\u8981\u6027\u304c\u4e88\u6e2c\u3055\u308c\u308b\u5834\u5408\u306f\u3001\u305d\u308c\u3089\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u306b\u554f\u984c\u306f\u3042\u308a\u307e\u305b\u3093\u3002
"},{"location":"ja/#5","title":"\u30a4\u30f3\u30bf\u30d5\u30a7\u30fc\u30b9\u6c5a\u67d3 (#5)","text":"\u8981\u7d04\u62bd\u8c61\u5316\u306f\u4f5c\u6210\u3055\u308c\u308b\u3079\u304d\u3082\u306e\u3067\u306f\u306a\u304f\u3001\u767a\u898b\u3055\u308c\u308b\u3079\u304d\u3082\u306e\u3067\u3059\u3002\u4e0d\u5fc5\u8981\u306a\u8907\u96d1\u3055\u3092\u907f\u3051\u308b\u305f\u3081\u306b\u3001\u30a4\u30f3\u30bf\u30d5\u30a7\u30fc\u30b9\u306f\u3001\u5fc5\u8981\u306b\u306a\u308b\u3068\u4e88\u6e2c\u3057\u305f\u3068\u304d\u3067\u306f\u306a\u304f\u3001\u5fc5\u8981\u306b\u306a\u3063\u305f\u3068\u304d\u306b\u4f5c\u6210\u3059\u308b\u304b\u3001\u5c11\u306a\u304f\u3068\u3082\u62bd\u8c61\u5316\u304c\u6709\u52b9\u3067\u3042\u308b\u3053\u3068\u3092\u8a3c\u660e\u3067\u304d\u308b\u5834\u5408\u306b\u4f5c\u6210\u3057\u3066\u304f\u3060\u3055\u3044\u3002
\u30a4\u30f3\u30bf\u30d5\u30a7\u30fc\u30b9\u306f\u3001\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u52d5\u4f5c\u3092\u6307\u5b9a\u3059\u308b\u65b9\u6cd5\u3092\u63d0\u4f9b\u3057\u307e\u3059\u3002\u8907\u6570\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u304c\u5b9f\u88c5\u3067\u304d\u308b\u5171\u901a\u9805\u3092\u62bd\u51fa\u3059\u308b\u305f\u3081\u306b\u3001\u30a4\u30f3\u30bf\u30d5\u30a7\u30fc\u30b9\u306f\u4f7f\u7528\u3055\u308c\u307e\u3059\u3002Go\u8a00\u8a9e\u306e\u30a4\u30f3\u30bf\u30d5\u30a7\u30fc\u30b9\u304c\u5927\u304d\u304f\u7570\u306a\u308b\u306e\u306f\u3001\u6697\u9ed9\u7684\u306b\u6e80\u305f\u3055\u308c\u308b\u3053\u3068\u3067\u3059\u3002\u30aa\u30d6\u30b8\u30a7\u30af\u30c8 X
\u304c\u30a4\u30f3\u30bf\u30d5\u30a7\u30fc\u30b9 Y
\u3092\u5b9f\u88c5\u3057\u3066\u3044\u308b\u3053\u3068\u3092\u793a\u3059 implements
\u306e\u3088\u3046\u306a\u660e\u793a\u7684\u306a\u30ad\u30fc\u30ef\u30fc\u30c9\u306f\u3042\u308a\u307e\u305b\u3093\u3002
\u4e00\u822c\u306b\u3001\u30a4\u30f3\u30bf\u30d5\u30a7\u30fc\u30b9\u304c\u4fa1\u5024\u3092\u3082\u305f\u3089\u3059\u3068\u8003\u3048\u3089\u308c\u308b\u4e3b\u8981\u306a\u4f7f\u7528\u4f8b\u306f\uff13\u3064\u3042\u308a\u307e\u3059\u3002\u305d\u308c\u306f\u3001\u5171\u901a\u306e\u52d5\u4f5c\u3092\u9664\u5916\u3059\u308b\u3001\u4f55\u3089\u304b\u306e\u5206\u96e2\u3092\u4f5c\u6210\u3059\u308b\u3001\u304a\u3088\u3073\u578b\u3092\u7279\u5b9a\u306e\u52d5\u4f5c\u306b\u5236\u9650\u3059\u308b\u3068\u3044\u3046\u3082\u306e\u3067\u3059\u3002\u305f\u3060\u3057\u3001\u3053\u306e\u30ea\u30b9\u30c8\u306f\u3059\u3079\u3066\u3092\u7db2\u7f85\u3057\u3066\u3044\u308b\u308f\u3051\u3067\u306f\u306a\u304f\u3001\u76f4\u9762\u3059\u308b\u72b6\u6cc1\u306b\u3088\u3063\u3066\u3082\u7570\u306a\u308a\u307e\u3059\u3002
\u591a\u304f\u306e\u5834\u5408\u3001\u30a4\u30f3\u30bf\u30d5\u30a7\u30fc\u30b9\u306f\u62bd\u8c61\u5316\u3059\u308b\u305f\u3081\u306b\u4f5c\u6210\u3055\u308c\u307e\u3059\u3002\u305d\u3057\u3066\u3001\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u3067\u62bd\u8c61\u5316\u3059\u308b\u3068\u304d\u306e\u4e3b\u306a\u6ce8\u610f\u70b9\u306f\u3001\u62bd\u8c61\u5316\u306f\u4f5c\u6210\u3055\u308c\u308b\u3079\u304d\u3067\u306f\u306a\u304f\u3001\u767a\u898b\u3055\u308c\u308b\u3079\u304d\u3067\u3042\u308b\u3068\u3044\u3046\u3053\u3068\u3092\u899a\u3048\u3066\u304a\u304f\u3053\u3068\u3067\u3059\u3002\u3059\u306a\u308f\u3061\u3001\u305d\u3046\u3059\u308b\u76f4\u63a5\u306e\u7406\u7531\u304c\u306a\u3044\u9650\u308a\u3001\u30b3\u30fc\u30c9\u5185\u3067\u62bd\u8c61\u5316\u3059\u3079\u304d\u3067\u306f\u306a\u3044\u3068\u3044\u3046\u3053\u3068\u3067\u3059\u3002\u30a4\u30f3\u30bf\u30d5\u30a7\u30fc\u30b9\u3092\u4f7f\u3063\u3066\u8a2d\u8a08\u3059\u308b\u306e\u3067\u306f\u306a\u304f\u3001\u5177\u4f53\u7684\u306a\u30cb\u30fc\u30ba\u3092\u5f85\u3064\u3079\u304d\u3067\u3059\u3002\u5225\u306e\u8a00\u3044\u65b9\u3092\u3059\u308c\u3070\u3001\u30a4\u30f3\u30bf\u30d5\u30a7\u30fc\u30b9\u306f\u5fc5\u8981\u306b\u306a\u308b\u3068\u4e88\u6e2c\u3057\u305f\u3068\u304d\u3067\u306f\u306a\u304f\u3001\u5fc5\u8981\u306b\u306a\u3063\u305f\u3068\u304d\u306b\u4f5c\u6210\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002 \u30a4\u30f3\u30bf\u30d5\u30a7\u30fc\u30b9\u306e\u904e\u5ea6\u306a\u4f7f\u7528\u3092\u3057\u305f\u5834\u5408\u306e\u4e3b\u306a\u554f\u984c\u306f\u4f55\u3067\u3057\u3087\u3046\u304b\u3002\u7b54\u3048\u306f\u3001\u30b3\u30fc\u30c9\u30d5\u30ed\u30fc\u304c\u3088\u308a\u8907\u96d1\u306b\u306a\u308b\u3053\u3068\u3067\u3059\u3002\u5f79\u306b\u7acb\u305f\u306a\u3044\u9593\u63a5\u53c2\u7167\u3092\u8ffd\u52a0\u3057\u3066\u3082\u4f55\u306e\u4fa1\u5024\u3082\u3042\u308a\u307e\u305b\u3093\u3002\u305d\u308c\u306f\u4fa1\u5024\u306e\u306a\u3044\u62bd\u8c61\u5316\u3092\u3059\u308b\u3053\u3068\u3067\u3001\u30b3\u30fc\u30c9\u3092\u8aad\u307f\u3001\u7406\u89e3\u3057\u3001\u63a8\u8ad6\u3059\u308b\u3053\u3068\u3092\u3055\u3089\u306b\u56f0\u96e3\u306b\u3057\u307e\u3059\u3002\u30a4\u30f3\u30bf\u30d5\u30a7\u30fc\u30b9\u3092\u8ffd\u52a0\u3059\u308b\u660e\u78ba\u306a\u7406\u7531\u304c\u306a\u304f\u3001\u30a4\u30f3\u30bf\u30d5\u30a7\u30fc\u30b9\u306b\u3088\u3063\u3066\u30b3\u30fc\u30c9\u304c\u3069\u306e\u3088\u3046\u306b\u6539\u5584\u3055\u308c\u308b\u304b\u304c\u4e0d\u660e\u77ad\u306a\u5834\u5408\u306f\u3001\u305d\u306e\u30a4\u30f3\u30bf\u30d5\u30a7\u30fc\u30b9\u306e\u76ee\u7684\u306b\u7570\u8b70\u3092\u5531\u3048\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u5b9f\u88c5\u3092\u76f4\u63a5\u547c\u3073\u51fa\u3059\u306e\u3082\u4e00\u3064\u306e\u624b\u3067\u3059\u3002
\u30b3\u30fc\u30c9\u5185\u3067\u62bd\u8c61\u5316\u3059\u308b\u3068\u304d\u306f\u6ce8\u610f\u304c\u5fc5\u8981\u3067\u3059\uff08\u62bd\u8c61\u5316\u306f\u4f5c\u6210\u3059\u308b\u306e\u3067\u306f\u306a\u304f\u3001\u767a\u898b\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\uff09\u3002\u5f8c\u3067\u5fc5\u8981\u306b\u306a\u308b\u53ef\u80fd\u6027\u304c\u3042\u308b\u3082\u306e\u3092\u8003\u616e\u3057\u3001\u5b8c\u74a7\u306a\u62bd\u8c61\u5316\u30ec\u30d9\u30eb\u3092\u63a8\u6e2c\u3057\u3066\u3001\u79c1\u305f\u3061\u30bd\u30d5\u30c8\u30a6\u30a7\u30a2\u958b\u767a\u8005\u306f\u30b3\u30fc\u30c9\u3092\u30aa\u30fc\u30d0\u30fc\u30a8\u30f3\u30b8\u30cb\u30a2\u30ea\u30f3\u30b0\u3059\u308b\u3053\u3068\u304c\u3088\u304f\u3042\u308a\u307e\u3059\u3002\u307b\u3068\u3093\u3069\u306e\u5834\u5408\u3001\u30b3\u30fc\u30c9\u304c\u4e0d\u5fc5\u8981\u306a\u62bd\u8c61\u5316\u3067\u6c5a\u67d3\u3055\u308c\u3001\u8aad\u307f\u306b\u304f\u304f\u306a\u308b\u305f\u3081\u3001\u3053\u306e\u30d7\u30ed\u30bb\u30b9\u306f\u907f\u3051\u308b\u3079\u304d\u3067\u3059\u3002
\u30ed\u30d6\u30fb\u30d1\u30a4\u30af
\u30a4\u30f3\u30bf\u30d5\u30a7\u30fc\u30b9\u3067\u30c7\u30b6\u30a4\u30f3\u3059\u308b\u306a\u3002\u30a4\u30f3\u30bf\u30d5\u30a7\u30fc\u30b9\u3092\u898b\u3064\u3051\u51fa\u305b\u3002
\u62bd\u8c61\u7684\u306b\u554f\u984c\u3092\u89e3\u6c7a\u3057\u3088\u3046\u3068\u3059\u308b\u306e\u3067\u306f\u306a\u304f\u3001\u4eca\u89e3\u6c7a\u3059\u3079\u304d\u3053\u3068\u3092\u89e3\u6c7a\u3057\u307e\u3057\u3087\u3046\u3002\u6700\u5f8c\u306b\u91cd\u8981\u306a\u3053\u3068\u3067\u3059\u304c\u3001\u30a4\u30f3\u30bf\u30d5\u30a7\u30fc\u30b9\u306b\u3088\u3063\u3066\u30b3\u30fc\u30c9\u304c\u3069\u306e\u3088\u3046\u306b\u6539\u5584\u3055\u308c\u308b\u304b\u304c\u4e0d\u660e\u77ad\u306a\u5834\u5408\u306f\u3001\u30b3\u30fc\u30c9\u3092\u7c21\u7d20\u5316\u3059\u308b\u305f\u3081\u306b\u30a4\u30f3\u30bf\u30d5\u30a7\u30fc\u30b9\u3092\u524a\u9664\u3059\u308b\u3053\u3068\u3092\u691c\u8a0e\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u3067\u3057\u3087\u3046\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#6","title":"\u751f\u7523\u8005\u5074\u306e\u30a4\u30f3\u30bf\u30d5\u30a7\u30fc\u30b9 (#6)","text":"\u8981\u7d04\u30a4\u30f3\u30bf\u30d5\u30a7\u30fc\u30b9\u3092\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u5074\u3067\u4fdd\u6301\u3059\u308b\u3053\u3068\u3067\u4e0d\u5fc5\u8981\u306a\u62bd\u8c61\u5316\u3092\u56de\u907f\u3067\u304d\u307e\u3059\u3002
Go\u8a00\u8a9e\u3067\u306f\u30a4\u30f3\u30bf\u30d5\u30a7\u30fc\u30b9\u304c\u6697\u9ed9\u7684\u306b\u6e80\u305f\u3055\u308c\u307e\u3059\u3002\u3053\u308c\u306f\u3001\u660e\u793a\u7684\u306a\u5b9f\u88c5\u3092\u6301\u3064\u8a00\u8a9e\u3068\u6bd4\u8f03\u3057\u3066\u5927\u304d\u306a\u5909\u5316\u3092\u3082\u305f\u3089\u3059\u50be\u5411\u304c\u3042\u308a\u307e\u3059\u3002\u307b\u3068\u3093\u3069\u306e\u5834\u5408\u3001\u5f93\u3046\u3079\u304d\u30a2\u30d7\u30ed\u30fc\u30c1\u306f\u524d\u306e\u30bb\u30af\u30b7\u30e7\u30f3\u3067\u8aac\u660e\u3057\u305f\u3082\u306e\u2015\u2015\u62bd\u8c61\u5316\u306f\u4f5c\u6210\u3059\u308b\u306e\u3067\u306f\u306a\u304f\u3001\u767a\u898b\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u2015\u2015\u306b\u4f3c\u3066\u3044\u307e\u3059\u3002\u3053\u308c\u306f\u3001\u3059\u3079\u3066\u306e\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u306b\u5bfe\u3057\u3066\u7279\u5b9a\u306e\u62bd\u8c61\u5316\u3092\u5f37\u5236\u3059\u308b\u306e\u306f\u751f\u7523\u8005\u306e\u5f79\u5272\u3067\u306f\u306a\u3044\u3053\u3068\u3092\u610f\u5473\u3057\u307e\u3059\u3002\u4ee3\u308f\u308a\u306b\u3001\u4f55\u3089\u304b\u306e\u5f62\u5f0f\u306e\u62bd\u8c61\u5316\u304c\u5fc5\u8981\u304b\u3069\u3046\u304b\u3092\u5224\u65ad\u3057\u3001\u305d\u306e\u30cb\u30fc\u30ba\u306b\u6700\u9069\u306a\u62bd\u8c61\u5316\u30ec\u30d9\u30eb\u3092\u6c7a\u5b9a\u3059\u308b\u306e\u306f\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u306e\u8cac\u4efb\u3067\u3059\u3002
\u307b\u3068\u3093\u3069\u306e\u5834\u5408\u3001\u30a4\u30f3\u30bf\u30d5\u30a7\u30fc\u30b9\u306f\u6d88\u8cbb\u8005\u5074\u306b\u5b58\u5728\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u305f\u3060\u3057\u3001\u7279\u5b9a\u306e\u72b6\u6cc1\uff08\u305f\u3068\u3048\u3070\u3001\u62bd\u8c61\u5316\u304c\u6d88\u8cbb\u8005\u306b\u3068\u3063\u3066\u5f79\u7acb\u3064\u3053\u3068\u304c\u308f\u304b\u3063\u3066\u3044\u308b\u2015\u2015\u4e88\u6e2c\u306f\u3057\u3066\u3044\u306a\u3044\u2015\u2015\u5834\u5408\uff09\u3067\u306f\u3001\u305d\u308c\u3092\u751f\u7523\u8005\u5074\u3067\u4f7f\u7528\u3057\u305f\u3044\u5834\u5408\u304c\u3042\u308a\u307e\u3059\u3002\u305d\u3046\u3057\u305f\u5834\u5408\u3001\u53ef\u80fd\u306a\u9650\u308a\u6700\u5c0f\u9650\u306b\u6291\u3048\u3001\u518d\u5229\u7528\u53ef\u80fd\u6027\u3092\u9ad8\u3081\u3001\u3088\u308a\u7c21\u5358\u306b\u69cb\u6210\u3067\u304d\u308b\u3088\u3046\u306b\u52aa\u3081\u308b\u3079\u304d\u3067\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#7","title":"\u30a4\u30f3\u30bf\u30d5\u30a7\u30fc\u30b9\u3092\u8fd4\u3059 (#7)","text":"\u8981\u7d04\u67d4\u8edf\u6027\u306b\u554f\u984c\u304c\u306a\u3044\u3088\u3046\u306b\u3059\u308b\u305f\u3081\u306b\u3001\u95a2\u6570\u306f\u307b\u3068\u3093\u3069\u306e\u5834\u5408\u3001\u30a4\u30f3\u30bf\u30d5\u30a7\u30fc\u30b9\u3067\u306f\u306a\u304f\u5177\u4f53\u7684\u200b\u200b\u306a\u5b9f\u88c5\u3092\u8fd4\u3059\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u9006\u306b\u3001\u95a2\u6570\u306f\u53ef\u80fd\u306a\u9650\u308a\u30a4\u30f3\u30bf\u30d5\u30a7\u30fc\u30b9\u3092\u53d7\u3051\u5165\u308c\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002
\u307b\u3068\u3093\u3069\u306e\u5834\u5408\u3001\u30a4\u30f3\u30bf\u30d5\u30a7\u30fc\u30b9\u3067\u306f\u306a\u304f\u5177\u4f53\u7684\u306a\u5b9f\u88c5\u3092\u8fd4\u3059\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u305d\u3046\u3067\u306a\u3044\u3068\u30d1\u30c3\u30b1\u30fc\u30b8\u306e\u4f9d\u5b58\u95a2\u4fc2\u306b\u3088\u308a\u8a2d\u8a08\u304c\u3044\u3063\u305d\u3046\u8907\u96d1\u306b\u306a\u308a\u3001\u3059\u3079\u3066\u306e\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u304c\u540c\u3058\u62bd\u8c61\u5316\u306b\u4f9d\u5b58\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u305f\u3081\u3001\u67d4\u8edf\u6027\u306b\u6b20\u3051\u308b\u53ef\u80fd\u6027\u304c\u3042\u308a\u307e\u3059\u3002\u7d50\u8ad6\u306f\u524d\u306e\u30bb\u30af\u30b7\u30e7\u30f3\u3068\u4f3c\u3066\u3044\u307e\u3059\u3002\u62bd\u8c61\u5316\u304c\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u306b\u3068\u3063\u3066\u5f79\u7acb\u3064\u3053\u3068\u304c\uff08\u4e88\u6e2c\u3055\u308c\u308b\u3067\u306f\u306a\u304f\uff09\u308f\u304b\u3063\u3066\u3044\u308b\u5834\u5408\u306f\u3001\u30a4\u30f3\u30bf\u30d5\u30a7\u30fc\u30b9\u3092\u8fd4\u3059\u3053\u3068\u3092\u691c\u8a0e\u3057\u3066\u3082\u3088\u3044\u3067\u3057\u3087\u3046\u3002\u305d\u308c\u4ee5\u5916\u306e\u5834\u5408\u306f\u3001\u62bd\u8c61\u5316\u3092\u5f37\u5236\u3059\u3079\u304d\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u3002\u305d\u308c\u3089\u306f\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u306b\u3088\u3063\u3066\u767a\u898b\u3055\u308c\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u4f55\u3089\u304b\u306e\u7406\u7531\u3067\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u304c\u5b9f\u88c5\u3092\u62bd\u8c61\u5316\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u5834\u5408\u3067\u3082\u3001\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u5074\u3067\u305d\u308c\u3092\u884c\u3046\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002
"},{"location":"ja/#any-8","title":"any
\u306f\u4f55\u3082\u8a00\u308f\u306a\u3044 (#8)","text":"\u8981\u7d04 json.Marshal
\u306a\u3069\u8003\u3048\u3046\u308b\u3059\u3079\u3066\u306e\u578b\u3092\u53d7\u3051\u5165\u308c\u308b\u304b\u8fd4\u3059\u5fc5\u8981\u304c\u3042\u308b\u5834\u5408\u306b\u306e\u307f any
\u3092\u4f7f\u7528\u3057\u3066\u304f\u3060\u3055\u3044\u3002\u305d\u308c\u4ee5\u5916\u306e\u5834\u5408\u3001any
\u306f\u610f\u5473\u306e\u3042\u308b\u60c5\u5831\u3092\u63d0\u4f9b\u305b\u305a\u3001\u547c\u3073\u51fa\u3057\u5143\u304c\u4efb\u610f\u306e\u30c7\u30fc\u30bf\u578b\u306e\u30e1\u30bd\u30c3\u30c9\u3092\u547c\u3073\u51fa\u3059\u3053\u3068\u3092\u8a31\u53ef\u3059\u308b\u305f\u3081\u3001\u30b3\u30f3\u30d1\u30a4\u30eb\u6642\u306b\u554f\u984c\u304c\u767a\u751f\u3059\u308b\u53ef\u80fd\u6027\u304c\u3042\u308a\u307e\u3059\u3002
any
\u578b\u306f\u3001\u8003\u3048\u3046\u308b\u3059\u3079\u3066\u306e\u578b\u3092\u53d7\u3051\u5165\u308c\u308b\u304b\u8fd4\u3059\u5fc5\u8981\u304c\u3042\u308b\u5834\u5408\uff08\u305f\u3068\u3048\u3070\u3001\u30de\u30fc\u30b7\u30e3\u30ea\u30f3\u30b0\u3084\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u306e\u5834\u5408\uff09\u306b\u5f79\u7acb\u3061\u307e\u3059\u3002\u539f\u5247\u3068\u3057\u3066\u30b3\u30fc\u30c9\u3092\u904e\u5ea6\u306b\u4e00\u822c\u5316\u3059\u308b\u3053\u3068\u306f\u4f55\u3068\u3057\u3066\u3082\u907f\u3051\u308b\u3079\u304d\u3067\u3059\u3002\u30b3\u30fc\u30c9\u306e\u8868\u73fe\u529b\u306a\u3069\u306e\u4ed6\u306e\u5074\u9762\u304c\u5411\u4e0a\u3059\u308b\u5834\u5408\u306f\u3001\u30b3\u30fc\u30c9\u3092\u5c11\u3057\u91cd\u8907\u3055\u305b\u305f\u307b\u3046\u304c\u826f\u3044\u3053\u3068\u3082\u3042\u308a\u307e\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#9","title":"\u30b8\u30a7\u30cd\u30ea\u30c3\u30af\u30b9\u3092\u3044\u3064\u4f7f\u7528\u3059\u308b\u3079\u304d\u304b\u7406\u89e3\u3057\u3066\u3044\u306a\u3044 (#9)","text":"\u8981\u7d04\u30b8\u30a7\u30cd\u30ea\u30c3\u30af\u30b9\u3068\u578b\u30d1\u30e9\u30e1\u30fc\u30bf\u30fc\u3092\u5229\u7528\u3059\u308b\u3053\u3068\u3067\u3001\u8981\u7d20\u3084\u52d5\u4f5c\u3092\u9664\u5916\u3059\u308b\u305f\u3081\u306e\u30dc\u30a4\u30e9\u30fc\u30d7\u30ec\u30fc\u30c8\u30b3\u30fc\u30c9\u3092\u907f\u3051\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u305f\u3060\u3057\u3001\u578b\u30d1\u30e9\u30e1\u30fc\u30bf\u306f\u6642\u671f\u5c1a\u65e9\u306b\u4f7f\u7528\u305b\u305a\u3001\u5177\u4f53\u7684\u306a\u5fc5\u8981\u6027\u304c\u308f\u304b\u3063\u305f\u5834\u5408\u306b\u306e\u307f\u4f7f\u7528\u3057\u3066\u304f\u3060\u3055\u3044\u3002\u305d\u3046\u3067\u306a\u3051\u308c\u3070\u3001\u4e0d\u5fc5\u8981\u306a\u62bd\u8c61\u5316\u3068\u8907\u96d1\u3055\u304c\u751f\u3058\u307e\u3059\u3002
\u30bb\u30af\u30b7\u30e7\u30f3\u5168\u6587\u306f\u3053\u3061\u3089\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#10","title":"\u578b\u306e\u57cb\u3081\u8fbc\u307f\u3067\u8d77\u3053\u308a\u3046\u308b\u554f\u984c\u3092\u628a\u63e1\u3057\u3066\u3044\u306a\u3044 (#10)","text":"\u8981\u7d04\u578b\u57cb\u3081\u8fbc\u307f\u3092\u4f7f\u7528\u3059\u308b\u3068\u3001\u30dc\u30a4\u30e9\u30fc\u30d7\u30ec\u30fc\u30c8\u30b3\u30fc\u30c9\u3092\u56de\u907f\u3059\u308b\u3053\u3068\u3082\u3067\u304d\u307e\u3059\u3002\u305f\u3060\u3057\u3001\u305d\u3046\u3059\u308b\u3053\u3068\u3067\u3001\u4e00\u90e8\u306e\u30d5\u30a3\u30fc\u30eb\u30c9\u3092\u975e\u8868\u793a\u306b\u3057\u3066\u304a\u304f\u5fc5\u8981\u304c\u3042\u308b\u5834\u5408\u306b\u554f\u984c\u304c\u767a\u751f\u3057\u306a\u3044\u3088\u3046\u306b\u3057\u3066\u304f\u3060\u3055\u3044\u3002
\u69cb\u9020\u4f53\u3092\u4f5c\u6210\u3059\u308b\u3068\u304d\u3001Go\u8a00\u8a9e\u306f\u578b\u3092\u57cb\u3081\u8fbc\u3080\u30aa\u30d7\u30b7\u30e7\u30f3\u3092\u63d0\u4f9b\u3057\u307e\u3059\u3002\u305f\u3060\u3057\u3001\u578b\u57cb\u3081\u8fbc\u307f\u306e\u610f\u5473\u3092\u3059\u3079\u3066\u7406\u89e3\u3057\u3066\u3044\u306a\u3044\u3068\u3001\u4e88\u60f3\u5916\u306e\u52d5\u4f5c\u304c\u767a\u751f\u3059\u308b\u53ef\u80fd\u6027\u304c\u3042\u308a\u307e\u3059\u3002\u3053\u306e\u30bb\u30af\u30b7\u30e7\u30f3\u3067\u306f\u3001\u578b\u3092\u57cb\u3081\u8fbc\u3080\u65b9\u6cd5\u3001\u305d\u308c\u304c\u3082\u305f\u3089\u3059\u3082\u306e\u3001\u304a\u3088\u3073\u8003\u3048\u3089\u308c\u308b\u554f\u984c\u306b\u3064\u3044\u3066\u898b\u3066\u3044\u304d\u307e\u3059\u3002
Go\u8a00\u8a9e\u3067\u306f\u3001\u540d\u524d\u306a\u3057\u3067\u5ba3\u8a00\u3055\u308c\u305f\u69cb\u9020\u4f53\u30d5\u30a3\u30fc\u30eb\u30c9\u306f\u3001\u57cb\u3081\u8fbc\u307f\u3068\u547c\u3070\u308c\u307e\u3059\u3002\u305f\u3068\u3048\u3070\u3001\u6b21\u306e\u3088\u3046\u306a\u3082\u306e\u3067\u3059\u3002
type Foo struct {\n Bar // \u57cb\u3081\u8fbc\u307f\u30d5\u30a3\u30fc\u30eb\u30c9\n}\n\ntype Bar struct {\n Baz int\n}\n
Foo
\u69cb\u9020\u4f53\u3067\u306f\u3001Bar
\u578b\u304c\u95a2\u9023\u4ed8\u3051\u3089\u308c\u305f\u540d\u524d\u306a\u3057\u3067\u5ba3\u8a00\u3055\u308c\u3066\u3044\u307e\u3059\u3002\u3057\u305f\u304c\u3063\u3066\u3001\u3053\u308c\u306f\u57cb\u3081\u8fbc\u307f\u30d5\u30a3\u30fc\u30eb\u30c9\u3067\u3059\u3002
\u57cb\u3081\u8fbc\u307f\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u3067\u3001\u57cb\u3081\u8fbc\u307f\u578b\u306e\u30d5\u30a3\u30fc\u30eb\u30c9\u3068\u30e1\u30bd\u30c3\u30c9\u306f\u6607\u683c\u3057\u307e\u3059\u3002Bar \u306b\u306f Baz \u30d5\u30a3\u30fc\u30eb\u30c9\u304c\u542b\u307e\u308c\u3066\u3044\u308b\u305f\u3081\u3001\u3053\u306e\u30d5\u30a3\u30fc\u30eb\u30c9\u306f Foo
\u306b\u6607\u683c\u3057\u307e\u3059\u3002\u3057\u305f\u304c\u3063\u3066\u3001Foo \u304b\u3089 Baz \u3092\u5229\u7528\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002
\u578b\u306e\u57cb\u3081\u8fbc\u307f\u306b\u3064\u3044\u3066\u4f55\u304c\u8a00\u3048\u308b\u3067\u3057\u3087\u3046\u304b\u3002\u307e\u305a\u3001\u3053\u308c\u304c\u5fc5\u8981\u306b\u306a\u308b\u3053\u3068\u306f\u307b\u3068\u3093\u3069\u306a\u304f\u3001\u30e6\u30fc\u30b9\u30b1\u30fc\u30b9\u304c\u4f55\u3067\u3042\u308c\u3001\u304a\u305d\u3089\u304f\u578b\u57cb\u3081\u8fbc\u307f\u306a\u3057\u3067\u3082\u540c\u69d8\u306b\u89e3\u6c7a\u3067\u304d\u308b\u3053\u3068\u3092\u610f\u5473\u3057\u307e\u3059\u3002\u578b\u306e\u57cb\u3081\u8fbc\u307f\u306f\u4e3b\u306b\u5229\u4fbf\u6027\u3092\u76ee\u7684\u3068\u3057\u3066\u4f7f\u7528\u3055\u308c\u307e\u3059\u3002\u307b\u3068\u3093\u3069\u306e\u5834\u5408\u3001\u305d\u308c\u306f\u52d5\u4f5c\u3092\u6607\u683c\u3059\u308b\u305f\u3081\u306b\u4f7f\u7528\u3055\u308c\u307e\u3059\u3002
\u578b\u57cb\u3081\u8fbc\u307f\u3092\u4f7f\u7528\u3059\u308b\u5834\u5408\u306f\u3001\u6b21\u306e 2 \u3064\u306e\u4e3b\u306a\u5236\u7d04\u3092\u5ff5\u982d\u306b\u7f6e\u304f\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002
Foo.Bar.Baz()
\u306e\u4ee3\u308f\u308a\u306b Foo.Baz()
\u306a\u3069\uff09\u3002 \u3053\u308c\u304c\u552f\u4e00\u306e\u6839\u62e0\u3067\u3042\u308b\u5834\u5408\u306f\u3001\u5185\u90e8\u578b\u3092\u57cb\u3081\u8fbc\u307e\u305a\u3001\u4ee3\u308f\u308a\u306b\u30d5\u30a3\u30fc\u30eb\u30c9\u3092\u4f7f\u3044\u307e\u3057\u3087\u3046\u3002\u3053\u308c\u3089\u306e\u5236\u7d04\u3092\u5ff5\u982d\u306b\u7f6e\u3044\u3066\u578b\u57cb\u3081\u8fbc\u307f\u3092\u610f\u8b58\u7684\u306b\u4f7f\u7528\u3059\u308b\u3068\u3001\u8ffd\u52a0\u306e\u8ee2\u9001\u30e1\u30bd\u30c3\u30c9\u306b\u3088\u308b\u30dc\u30a4\u30e9\u30fc\u30d7\u30ec\u30fc\u30c8\u30b3\u30fc\u30c9\u3092\u56de\u907f\u3059\u308b\u306e\u306b\u5f79\u7acb\u3061\u307e\u3059\u3002\u305f\u3060\u3057\u3001\u898b\u305f\u76ee\u3060\u3051\u3092\u76ee\u7684\u3068\u3057\u305f\u308a\u3001\u96a0\u3059\u3079\u304d\u8981\u7d20\u3092\u6607\u683c\u3057\u305f\u308a\u3057\u306a\u3044\u3088\u3046\u306b\u6ce8\u610f\u3057\u307e\u3057\u3087\u3046\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#functional-options-11","title":"Functional Options \u30d1\u30bf\u30fc\u30f3\u3092\u4f7f\u7528\u3057\u3066\u3044\u306a\u3044 (#11)","text":"\u8981\u7d04API \u306b\u9069\u3057\u305f\u65b9\u6cd5\u3067\u30aa\u30d7\u30b7\u30e7\u30f3\u3092\u4fbf\u5229\u306b\u51e6\u7406\u3059\u308b\u306b\u306f\u3001Functional Options \u30d1\u30bf\u30fc\u30f3\u3092\u4f7f\u7528\u3057\u307e\u3057\u3087\u3046\u3002
\u3055\u307e\u3056\u307e\u306a\u5b9f\u88c5\u65b9\u6cd5\u304c\u5b58\u5728\u3057\u3001\u591a\u5c11\u306e\u9055\u3044\u306f\u3042\u308a\u307e\u3059\u304c\u3001\u4e3b\u306a\u8003\u3048\u65b9\u306f\u6b21\u306e\u3068\u304a\u308a\u3067\u3059\u3002
type Option func(options *options)
\u30a8\u30e9\u30fc\u3092\u8fd4\u3059\u95a2\u6570\u3067\u3059\u3002\u305f\u3068\u3048\u3070\u3001WithPort
\u306f\u30dd\u30fc\u30c8\u3092\u8868\u3059 int
\u5f15\u6570\u3092\u53d7\u3051\u53d6\u308a\u3001options
\u69cb\u9020\u4f53\u306e\u66f4\u65b0\u65b9\u6cd5\u3092\u8868\u3059 Option
\u578b\u3092\u8fd4\u3057\u307e\u3059\u3002type options struct {\n port *int\n}\n\ntype Option func(options *options) error\n\nfunc WithPort(port int) Option {\n return func(options *options) error {\n if port < 0 {\n return errors.New(\"port should be positive\")\n }\n options.port = &port\n return nil\n }\n}\n\nfunc NewServer(addr string, opts ...Option) ( *http.Server, error) { <1>\n var options options <2>\n for _, opt := range opts { <3>\n err := opt(&options) <4>\n if err != nil {\n return nil, err\n }\n }\n\n// \u3053\u306e\u6bb5\u968e\u3067\u3001options \u69cb\u9020\u4f53\u304c\u69cb\u7bc9\u3055\u308c\u3001\u69cb\u6210\u304c\u542b\u307e\u308c\u307e\u3059\u3002\n// \u3057\u305f\u304c\u3063\u3066\u3001\u30dd\u30fc\u30c8\u8a2d\u5b9a\u306b\u95a2\u9023\u3059\u308b\u30ed\u30b8\u30c3\u30af\u3092\u5b9f\u88c5\u3067\u304d\u307e\u3059\u3002\n var port int\n if options.port == nil {\n port = defaultHTTPPort\n } else {\n if *options.port == 0 {\n port = randomPort()\n } else {\n port = *options.port\n }\n }\n\n // ...\n}\n
Functional Options \u30d1\u30bf\u30fc\u30f3\u306f\u3001\u30aa\u30d7\u30b7\u30e7\u30f3\u3092\u51e6\u7406\u3059\u308b\u305f\u3081\u306e\u624b\u8efd\u3067 API \u30d5\u30ec\u30f3\u30c9\u30ea\u30fc\u306a\u65b9\u6cd5\u3092\u63d0\u4f9b\u3057\u307e\u3059\u3002 Builder \u30d1\u30bf\u30fc\u30f3\u306f\u6709\u52b9\u306a\u30aa\u30d7\u30b7\u30e7\u30f3\u3067\u3059\u304c\u3001\u3044\u304f\u3064\u304b\u306e\u5c0f\u3055\u306a\u6b20\u70b9\uff08\u7a7a\u306e\u53ef\u80fd\u6027\u304c\u3042\u308b\u69cb\u6210\u69cb\u9020\u4f53\u3092\u6e21\u3055\u306a\u3051\u308c\u3070\u306a\u3089\u306a\u3044\u3001\u307e\u305f\u306f\u30a8\u30e9\u30fc\u3092\u51e6\u7406\u3059\u308b\u65b9\u6cd5\u304c\u3042\u307e\u308a\u4fbf\u5229\u3067\u306f\u306a\u3044\uff09\u304c\u3042\u308a\u3001\u3053\u306e\u7a2e\u306e\u554f\u984c\u306b\u304a\u3044\u3066 Functional Options \u30d1\u30bf\u30fc\u30f3\u304cGo\u8a00\u8a9e\u306b\u304a\u3051\u308b\u6163\u7528\u7684\u306a\u5bfe\u51e6\u65b9\u6cd5\u306b\u306a\u308b\u50be\u5411\u304c\u3042\u308a\u307e\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#12","title":"\u8aa4\u3063\u305f\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u69cb\u6210 (\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u69cb\u9020\u3068\u30d1\u30c3\u30b1\u30fc\u30b8\u69cb\u6210) (#12)","text":"\u5168\u4f53\u7684\u306a\u69cb\u6210\u306b\u95a2\u3057\u3066\u306f\u3001\u3055\u307e\u3056\u307e\u306a\u8003\u3048\u65b9\u304c\u3042\u308a\u307e\u3059\u3002\u305f\u3068\u3048\u3070\u3001\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u30b3\u30f3\u30c6\u30ad\u30b9\u30c8\u3054\u3068\u306b\u6574\u7406\u3059\u3079\u304d\u304b\u3001\u305d\u308c\u3068\u3082\u30ec\u30a4\u30e4\u30fc\u3054\u3068\u306b\u6574\u7406\u3059\u3079\u304d\u304b\u3001\u305d\u308c\u306f\u597d\u307f\u306b\u3088\u3063\u3066\u7570\u306a\u308a\u307e\u3059\u3002\u30b3\u30f3\u30c6\u30ad\u30b9\u30c8\uff08\u9867\u5ba2\u30b3\u30f3\u30c6\u30ad\u30b9\u30c8\u3001\u5951\u7d04\u30b3\u30f3\u30c6\u30ad\u30b9\u30c8\u306a\u3069\uff09\u3054\u3068\u306b\u30b3\u30fc\u30c9\u3092\u30b0\u30eb\u30fc\u30d7\u5316\u3059\u308b\u3053\u3068\u3092\u9078\u3076\u5834\u5408\u3082\u3042\u308c\u3070\u3001\u516d\u89d2\u5f62\u306e\u30a2\u30fc\u30ad\u30c6\u30af\u30c1\u30e3\u539f\u5247\u306b\u5f93\u3046\u3053\u3068\u3068\u3001\u6280\u8853\u5c64\u3054\u3068\u306b\u30b0\u30eb\u30fc\u30d7\u5316\u3059\u308b\u3053\u3068\u3092\u9078\u3076\u5834\u5408\u3082\u3042\u308a\u307e\u3059\u3002\u79c1\u305f\u3061\u304c\u884c\u3046\u6c7a\u5b9a\u304c\u4e00\u8cab\u3057\u3066\u3044\u308b\u9650\u308a\u3001\u305d\u308c\u304c\u30e6\u30fc\u30b9\u30b1\u30fc\u30b9\u306b\u9069\u5408\u3059\u308b\u306a\u3089\u3001\u305d\u308c\u304c\u9593\u9055\u3063\u3066\u3044\u308b\u3053\u3068\u306f\u3042\u308a\u307e\u305b\u3093\u3002
\u30d1\u30c3\u30b1\u30fc\u30b8\u306b\u95a2\u3057\u3066\u306f\u3001\u5f93\u3046\u3079\u304d\u30d9\u30b9\u30c8\u30d7\u30e9\u30af\u30c6\u30a3\u30b9\u304c\u8907\u6570\u3042\u308a\u307e\u3059\u3002\u307e\u305a\u3001\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u304c\u904e\u5ea6\u306b\u8907\u96d1\u306b\u306a\u308b\u53ef\u80fd\u6027\u304c\u3042\u308b\u305f\u3081\u3001\u6642\u671f\u5c1a\u65e9\u306a\u30d1\u30c3\u30b1\u30fc\u30b8\u5316\u306f\u907f\u3051\u308b\u3079\u304d\u3067\u3059\u3002\u5834\u5408\u306b\u3088\u3063\u3066\u306f\u3001\u5b8c\u74a7\u306a\u69cb\u9020\u3092\u6700\u521d\u304b\u3089\u7121\u7406\u306b\u4f5c\u308d\u3046\u3068\u3059\u308b\u3088\u308a\u3082\u3001\u5358\u7d14\u306a\u69cb\u6210\u3092\u4f7f\u7528\u3057\u3001\u305d\u306e\u5185\u5bb9\u3092\u7406\u89e3\u3057\u305f\u4e0a\u3067\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3092\u767a\u5c55\u3055\u305b\u308b\u307b\u3046\u304c\u826f\u3044\u5834\u5408\u304c\u3042\u308a\u307e\u3059\u3002 \u7c92\u5ea6\u3082\u8003\u616e\u3059\u3079\u304d\u91cd\u8981\u306a\u70b9\u3067\u3059\u3002 1 \u3064\u307e\u305f\u306f 2 \u3064\u306e\u30d5\u30a1\u30a4\u30eb\u3060\u3051\u3092\u542b\u3080\u6570\u5341\u306e\u30ca\u30ce\u30d1\u30c3\u30b1\u30fc\u30b8\u3092\u4f5c\u6210\u3059\u308b\u3053\u3068\u306f\u907f\u3051\u308b\u3079\u304d\u3067\u3059\u3002\u305d\u306e\u5834\u5408\u3001\u304a\u305d\u3089\u304f\u3053\u308c\u3089\u306e\u30d1\u30c3\u30b1\u30fc\u30b8\u9593\u306e\u8ad6\u7406\u7684\u306a\u63a5\u7d9a\u306e\u4e00\u90e8\u304c\u629c\u3051\u843d\u3061\u3001\u8aad\u307f\u624b\u306b\u3068\u3063\u3066\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u304c\u7406\u89e3\u3057\u306b\u304f\u304f\u306a\u308b\u304b\u3089\u3067\u3059\u3002\u9006\u306b\u3001\u30d1\u30c3\u30b1\u30fc\u30b8\u540d\u306e\u610f\u5473\u3092\u8584\u3081\u308b\u3088\u3046\u306a\u5de8\u5927\u306a\u30d1\u30c3\u30b1\u30fc\u30b8\u3082\u907f\u3051\u308b\u3079\u304d\u3067\u3059\u3002
\u30d1\u30c3\u30b1\u30fc\u30b8\u306e\u540d\u524d\u4ed8\u3051\u3082\u6ce8\u610f\u3057\u3066\u884c\u3046\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\uff08\u958b\u767a\u8005\u306a\u3089\uff09\u8ab0\u3082\u304c\u77e5\u3063\u3066\u3044\u308b\u3088\u3046\u306b\u3001\u540d\u524d\u3092\u4ed8\u3051\u308b\u306e\u306f\u96e3\u3057\u3044\u3067\u3059\u3002\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u304c Go \u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3092\u7406\u89e3\u3057\u3084\u3059\u3044\u3088\u3046\u306b\u3001\u30d1\u30c3\u30b1\u30fc\u30b8\u306b\u542b\u307e\u308c\u308b\u3082\u306e\u3067\u306f\u306a\u304f\u3001\u63d0\u4f9b\u3059\u308b\u3082\u306e\u306b\u57fa\u3065\u3044\u3066\u30d1\u30c3\u30b1\u30fc\u30b8\u306b\u540d\u524d\u3092\u4ed8\u3051\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u307e\u305f\u3001\u30cd\u30fc\u30df\u30f3\u30b0\u306b\u306f\u610f\u5473\u306e\u3042\u308b\u3082\u306e\u3092\u4ed8\u3051\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u3057\u305f\u304c\u3063\u3066\u3001\u30d1\u30c3\u30b1\u30fc\u30b8\u540d\u306f\u77ed\u304f\u3001\u7c21\u6f54\u3067\u3001\u8868\u73fe\u529b\u8c4a\u304b\u3067\u3001\u6163\u4f8b\u306b\u3088\u308a\u5358\u4e00\u306e\u5c0f\u6587\u5b57\u306b\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002
\u4f55\u3092\u30a8\u30af\u30b9\u30dd\u30fc\u30c8\u3059\u308b\u304b\u306b\u3064\u3044\u3066\u306e\u30eb\u30fc\u30eb\u306f\u975e\u5e38\u306b\u7c21\u5358\u3067\u3059\u3002\u30d1\u30c3\u30b1\u30fc\u30b8\u9593\u306e\u7d50\u5408\u3092\u6e1b\u3089\u3057\u3001\u30a8\u30af\u30b9\u30dd\u30fc\u30c8\u3055\u308c\u308b\u4e0d\u8981\u306a\u8981\u7d20\u3092\u975e\u8868\u793a\u306b\u3059\u308b\u305f\u3081\u306b\u3001\u30a8\u30af\u30b9\u30dd\u30fc\u30c8\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u3082\u306e\u3092\u3067\u304d\u308b\u9650\u308a\u6700\u5c0f\u9650\u306b\u6291\u3048\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u8981\u7d20\u3092\u30a8\u30af\u30b9\u30dd\u30fc\u30c8\u3059\u308b\u304b\u3069\u3046\u304b\u4e0d\u660e\u306a\u5834\u5408\u306f\u3001\u30c7\u30d5\u30a9\u30eb\u30c8\u3067\u30a8\u30af\u30b9\u30dd\u30fc\u30c8\u3057\u306a\u3044\u3088\u3046\u306b\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u5f8c\u3067\u30a8\u30af\u30b9\u30dd\u30fc\u30c8\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u3053\u3068\u304c\u5224\u660e\u3057\u305f\u5834\u5408\u306f\u3001\u30b3\u30fc\u30c9\u3092\u8abf\u6574\u3067\u304d\u307e\u3059\u3002\u307e\u305f\u3001\u69cb\u9020\u4f53\u3092 encoding/json \u3067\u30a2\u30f3\u30de\u30fc\u30b7\u30e3\u30ea\u30f3\u30b0\u3067\u304d\u308b\u3088\u3046\u306b\u30d5\u30a3\u30fc\u30eb\u30c9\u3092\u30a8\u30af\u30b9\u30dd\u30fc\u30c8\u3059\u308b\u306a\u3069\u3001\u3044\u304f\u3064\u304b\u306e\u4f8b\u5916\u306b\u3082\u7559\u610f\u3057\u3066\u304f\u3060\u3055\u3044\u3002
\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3092\u69cb\u6210\u3059\u308b\u306e\u306f\u7c21\u5358\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u304c\u3001\u3053\u308c\u3089\u306e\u30eb\u30fc\u30eb\u306b\u5f93\u3046\u3053\u3068\u3067\u7dad\u6301\u304c\u5bb9\u6613\u306b\u306a\u308a\u307e\u3059\u3002\u305f\u3060\u3057\u3001\u4fdd\u5b88\u6027\u3092\u5bb9\u6613\u306b\u3059\u308b\u305f\u3081\u306b\u306f\u4e00\u8cab\u6027\u3082\u91cd\u8981\u3067\u3042\u308b\u3053\u3068\u306b\u6ce8\u610f\u3057\u3066\u304f\u3060\u3055\u3044\u3002\u3057\u305f\u304c\u3063\u3066\u3001\u30b3\u30fc\u30c9\u30d9\u30fc\u30b9\u5185\u3067\u53ef\u80fd\u306a\u9650\u308a\u4e00\u8cab\u6027\u3092\u4fdd\u3064\u3088\u3046\u306b\u3057\u307e\u3057\u3087\u3046\u3002
\u88dc\u8db3Go \u30c1\u30fc\u30e0\u306f Go \u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306e\u7d44\u7e54\u5316/\u69cb\u9020\u5316\u306b\u95a2\u3059\u308b\u516c\u5f0f\u30ac\u30a4\u30c9\u30e9\u30a4\u30f3\u3092 2023 \u5e74\u306b\u767a\u884c\u3057\u307e\u3057\u305f\uff1a go.dev/doc/modules/layout
"},{"location":"ja/#13","title":"\u30e6\u30fc\u30c6\u30a3\u30ea\u30c6\u30a3\u30d1\u30c3\u30b1\u30fc\u30b8\u306e\u4f5c\u6210 (#13)","text":"\u8981\u7d04\u540d\u524d\u4ed8\u3051\u306f\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u8a2d\u8a08\u306e\u91cd\u8981\u306a\u90e8\u5206\u3067\u3059\u3002common
\u3001util
\u3001shared
\u306e\u3088\u3046\u306a\u30d1\u30c3\u30b1\u30fc\u30b8\u3092\u4f5c\u6210\u3057\u3066\u3082\u3001\u8aad\u307f\u624b\u306b\u305d\u308c\u307b\u3069\u306e\u4fa1\u5024\u3092\u3082\u305f\u3089\u3057\u307e\u305b\u3093\u3002\u3053\u306e\u3088\u3046\u306a\u30d1\u30c3\u30b1\u30fc\u30b8\u3092\u610f\u5473\u306e\u3042\u308b\u5177\u4f53\u7684\u306a\u30d1\u30c3\u30b1\u30fc\u30b8\u540d\u306b\u30ea\u30d5\u30a1\u30af\u30bf\u30ea\u30f3\u30b0\u3057\u307e\u3057\u3087\u3046\u3002
\u307e\u305f\u3001\u30d1\u30c3\u30b1\u30fc\u30b8\u306b\u542b\u307e\u308c\u308b\u3082\u306e\u3067\u306f\u306a\u304f\u3001\u30d1\u30c3\u30b1\u30fc\u30b8\u304c\u63d0\u4f9b\u3059\u308b\u3082\u306e\u306b\u57fa\u3065\u3044\u3066\u30d1\u30c3\u30b1\u30fc\u30b8\u306b\u540d\u524d\u3092\u4ed8\u3051\u308b\u3068\u3001\u305d\u306e\u8868\u73fe\u529b\u3092\u9ad8\u3081\u308b\u52b9\u7387\u7684\u306a\u65b9\u6cd5\u306b\u306a\u308b\u3053\u3068\u306b\u3082\u7559\u610f\u3057\u3066\u304f\u3060\u3055\u3044\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#14","title":"\u30d1\u30c3\u30b1\u30fc\u30b8\u540d\u306e\u885d\u7a81\u3092\u7121\u8996\u3059\u308b (#14)","text":"\u8981\u7d04\u6df7\u4e71\u3001\u3055\u3089\u306b\u306f\u30d0\u30b0\u306b\u3064\u306a\u304c\u308a\u304b\u306d\u306a\u3044\u3001\u5909\u6570\u3068\u30d1\u30c3\u30b1\u30fc\u30b8\u9593\u306e\u540d\u524d\u306e\u885d\u7a81\u3092\u56de\u907f\u3059\u308b\u305f\u3081\u306b\u3001\u305d\u308c\u305e\u308c\u306b\u4e00\u610f\u306e\u540d\u524d\u3092\u4f7f\u7528\u3057\u307e\u3057\u3087\u3046\u3002\u3053\u308c\u304c\u4e0d\u53ef\u80fd\u306a\u5834\u5408\u306f\u3001\u30a4\u30f3\u30dd\u30fc\u30c8\u30a8\u30a4\u30ea\u30a2\u30b9\u3092\u4f7f\u7528\u3057\u3066\u4fee\u98fe\u5b50\u3092\u5909\u66f4\u3057\u3066\u30d1\u30c3\u30b1\u30fc\u30b8\u540d\u3068\u5909\u6570\u540d\u3092\u533a\u5225\u3059\u308b\u304b\u3001\u3088\u308a\u826f\u3044\u540d\u524d\u3092\u8003\u3048\u3066\u304f\u3060\u3055\u3044\u3002
\u30d1\u30c3\u30b1\u30fc\u30b8\u306e\u885d\u7a81\u306f\u3001\u5909\u6570\u540d\u304c\u65e2\u5b58\u306e\u30d1\u30c3\u30b1\u30fc\u30b8\u540d\u3068\u885d\u7a81\u3059\u308b\u5834\u5408\u306b\u767a\u751f\u3057\u3001\u30d1\u30c3\u30b1\u30fc\u30b8\u306e\u518d\u5229\u7528\u304c\u59a8\u3052\u3089\u308c\u307e\u3059\u3002\u66d6\u6627\u3055\u3092\u907f\u3051\u308b\u305f\u3081\u306b\u3001\u5909\u6570\u540d\u306e\u885d\u7a81\u3092\u9632\u3050\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u885d\u7a81\u304c\u767a\u751f\u3057\u305f\u5834\u5408\u306f\u3001\u5225\u306e\u610f\u5473\u306e\u3042\u308b\u540d\u524d\u3092\u898b\u3064\u3051\u308b\u304b\u3001\u30a4\u30f3\u30dd\u30fc\u30c8\u30a8\u30a4\u30ea\u30a2\u30b9\u3092\u4f7f\u7528\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002
"},{"location":"ja/#15","title":"\u30b3\u30fc\u30c9\u306e\u6587\u7ae0\u5316\u304c\u884c\u308f\u308c\u3066\u3044\u306a\u3044 (#15)","text":"\u8981\u7d04\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u3068\u30e1\u30f3\u30c6\u30ca\u304c\u30b3\u30fc\u30c9\u306e\u610f\u56f3\u3092\u7406\u89e3\u3067\u304d\u308b\u3088\u3046\u306b\u3001\u30a8\u30af\u30b9\u30dd\u30fc\u30c8\u3055\u308c\u305f\u8981\u7d20\u3092\u6587\u7ae0\u5316\u3057\u307e\u3057\u3087\u3046\u3002
\u6587\u7ae0\u5316\u306f\u30b3\u30fc\u30c7\u30a3\u30f3\u30b0\u306e\u91cd\u8981\u306a\u5074\u9762\u3067\u3059\u3002\u3053\u308c\u306b\u3088\u308a\u3001\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u304c API \u3092\u3088\u308a\u7c21\u5358\u306b\u4f7f\u7528\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u304c\u3001\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306e\u7dad\u6301\u306b\u3082\u5f79\u7acb\u3061\u307e\u3059\u3002Go\u8a00\u8a9e\u3067\u306f\u3001\u30b3\u30fc\u30c9\u3092\u6163\u7528\u7684\u306a\u3082\u306e\u306b\u3059\u308b\u305f\u3081\u306b\u3001\u3044\u304f\u3064\u304b\u306e\u30eb\u30fc\u30eb\u306b\u5f93\u3046\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002
\u307e\u305a\u3001\u30a8\u30af\u30b9\u30dd\u30fc\u30c8\u3055\u308c\u305f\u3059\u3079\u3066\u306e\u8981\u7d20\u3092\u6587\u7ae0\u5316\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u69cb\u9020\u3001\u30a4\u30f3\u30bf\u30d5\u30a7\u30fc\u30b9\u3001\u95a2\u6570\u306a\u3069\u3001\u30a8\u30af\u30b9\u30dd\u30fc\u30c8\u3059\u308b\u5834\u5408\u306f\u6587\u7ae0\u5316\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u6163\u4f8b\u3068\u3057\u3066\u3001\u30a8\u30af\u30b9\u30dd\u30fc\u30c8\u3055\u308c\u305f\u8981\u7d20\u306e\u540d\u524d\u304b\u3089\u59cb\u307e\u308b\u30b3\u30e1\u30f3\u30c8\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002
\u6163\u4f8b\u3068\u3057\u3066\u3001\u5404\u30b3\u30e1\u30f3\u30c8\u306f\u53e5\u8aad\u70b9\u3067\u7d42\u308f\u308b\u5b8c\u5168\u306a\u6587\u3067\u3042\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u307e\u305f\u3001\u95a2\u6570\uff08\u307e\u305f\u306f\u30e1\u30bd\u30c3\u30c9\uff09\u3092\u6587\u7ae0\u5316\u3059\u308b\u3068\u304d\u306f\u3001\u95a2\u6570\u304c\u3069\u306e\u3088\u3046\u306b\u5b9f\u884c\u3059\u308b\u304b\u3067\u306f\u306a\u304f\u3001\u305d\u306e\u95a2\u6570\u304c\u4f55\u3092\u5b9f\u884c\u3059\u308b\u3064\u3082\u308a\u3067\u3042\u308b\u304b\u3092\u5f37\u8abf\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u3053\u3068\u306b\u3082\u7559\u610f\u3057\u3066\u304f\u3060\u3055\u3044\u3002\u3053\u308c\u306f\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u3067\u306f\u306a\u304f\u3001\u95a2\u6570\u3068\u30b3\u30e1\u30f3\u30c8\u306b\u3064\u3044\u3066\u3067\u3059\u3002\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u306f\u7406\u60f3\u7684\u306b\u306f\u3001\u5229\u7528\u8005\u304c\u30a8\u30af\u30b9\u30dd\u30fc\u30c8\u3055\u308c\u305f\u8981\u7d20\u306e\u4f7f\u7528\u65b9\u6cd5\u3092\u7406\u89e3\u3059\u308b\u305f\u3081\u306b\u30b3\u30fc\u30c9\u3092\u898b\u308b\u5fc5\u8981\u304c\u306a\u3044\u307b\u3069\u5341\u5206\u306a\u60c5\u5831\u3092\u63d0\u4f9b\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002
\u5909\u6570\u307e\u305f\u306f\u5b9a\u6570\u3092\u6587\u7ae0\u5316\u3059\u308b\u5834\u5408\u3001\u305d\u306e\u76ee\u7684\u3068\u5185\u5bb9\u3068\u3044\u3046 2 \u3064\u306e\u5074\u9762\u3092\u4f1d\u3048\u308b\u3053\u3068\u304c\u91cd\u8981\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002\u524d\u8005\u306f\u3001\u5916\u90e8\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u306b\u3068\u3063\u3066\u5f79\u7acb\u3064\u3088\u3046\u306b\u3001\u30b3\u30fc\u30c9\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u3068\u3057\u3066\u5b58\u5728\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u305f\u3060\u3057\u3001\u5f8c\u8005\u306f\u5fc5\u305a\u3057\u3082\u516c\u958b\u3055\u308c\u308b\u3079\u304d\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u3002
\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u3068\u30e1\u30f3\u30c6\u30ca\u304c\u30d1\u30c3\u30b1\u30fc\u30b8\u306e\u76ee\u7684\u3092\u7406\u89e3\u3067\u304d\u308b\u3088\u3046\u306b\u3001\u5404\u30d1\u30c3\u30b1\u30fc\u30b8\u3092\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u3059\u308b\u5fc5\u8981\u3082\u3042\u308a\u307e\u3059\u3002\u6163\u4f8b\u3068\u3057\u3066\u3001\u30b3\u30e1\u30f3\u30c8\u306f //Package
\u3067\u59cb\u307e\u308a\u3001\u305d\u306e\u5f8c\u306b\u30d1\u30c3\u30b1\u30fc\u30b8\u540d\u304c\u7d9a\u304d\u307e\u3059\u3002\u30d1\u30c3\u30b1\u30fc\u30b8\u30b3\u30e1\u30f3\u30c8\u306e\u6700\u521d\u306e\u884c\u306f\u3001\u30d1\u30c3\u30b1\u30fc\u30b8\u306b\u8868\u793a\u3055\u308c\u308b\u305f\u3081\u7c21\u6f54\u306b\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u305d\u3057\u3066\u3001\u6b21\u306e\u884c\u306b\u5fc5\u8981\u306a\u60c5\u5831\u3092\u3059\u3079\u3066\u5165\u529b\u3057\u307e\u3059\u3002
\u30b3\u30fc\u30c9\u3092\u6587\u7ae0\u5316\u3059\u308b\u3053\u3068\u304c\u5236\u7d04\u306b\u306a\u308b\u3079\u304d\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u3002\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u3084\u30e1\u30f3\u30c6\u30ca\u304c\u30b3\u30fc\u30c9\u306e\u610f\u56f3\u3092\u7406\u89e3\u3059\u308b\u306e\u306b\u5f79\u7acb\u3064\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002
"},{"location":"ja/#16","title":"\u30ea\u30f3\u30bf\u30fc\u3092\u4f7f\u7528\u3057\u3066\u306a\u3044 (#16)","text":"\u8981\u7d04\u30b3\u30fc\u30c9\u306e\u54c1\u8cea\u3068\u4e00\u8cab\u6027\u3092\u5411\u4e0a\u3055\u305b\u308b\u306b\u306f\u3001\u30ea\u30f3\u30bf\u30fc\u3068\u30d5\u30a9\u30fc\u30de\u30c3\u30bf\u30fc\u3092\u4f7f\u7528\u3057\u307e\u3057\u3087\u3046
\u30ea\u30f3\u30bf\u30fc\u306f\u3001\u30b3\u30fc\u30c9\u3092\u5206\u6790\u3057\u3066\u30a8\u30e9\u30fc\u3092\u691c\u51fa\u3059\u308b\u81ea\u52d5\u30c4\u30fc\u30eb\u3067\u3059\u3002\u3053\u306e\u30bb\u30af\u30b7\u30e7\u30f3\u306e\u76ee\u7684\u306f\u3001\u65e2\u5b58\u306e\u30ea\u30f3\u30bf\u30fc\u306e\u5b8c\u5168\u306a\u30ea\u30b9\u30c8\u3092\u63d0\u4f9b\u3059\u308b\u3053\u3068\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u3002\u305d\u3046\u3057\u305f\u5834\u5408\u3001\u3059\u3050\u306b\u4f7f\u3044\u7269\u306b\u306a\u3089\u306a\u304f\u306a\u3063\u3066\u3057\u307e\u3046\u304b\u3089\u3067\u3059\u3002\u305f\u3060\u3057\u3001\u307b\u3068\u3093\u3069\u306e Go \u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306b\u30ea\u30f3\u30bf\u30fc\u304c\u4e0d\u53ef\u6b20\u3067\u3042\u308b\u3068\u3044\u3046\u3053\u3068\u306f\u7406\u89e3\u3057\u3001\u899a\u3048\u3066\u304a\u304d\u307e\u3057\u3087\u3046\u3002
\u30ea\u30f3\u30bf\u30fc\u306e\u307b\u304b\u306b\u3001\u30b3\u30fc\u30c9\u30b9\u30bf\u30a4\u30eb\u3092\u4fee\u6b63\u3059\u308b\u305f\u3081\u306b\u30b3\u30fc\u30c9\u30d5\u30a9\u30fc\u30de\u30c3\u30bf\u30fc\u3082\u4f7f\u7528\u3057\u307e\u3057\u3087\u3046\u3002\u4ee5\u4e0b\u306b\u3001\u3044\u304f\u3064\u304b\u306e\u30b3\u30fc\u30c9\u30d5\u30a9\u30fc\u30de\u30c3\u30bf\u30fc\u3092\u793a\u3057\u307e\u3059\u3002
\u307b\u304b\u306b golangci-lint (https://github.com/golangci/golangci-lint) \u3068\u3044\u3046\u3082\u306e\u304c\u3042\u308a\u307e\u3059\u3002\u3053\u308c\u306f\u3001\u591a\u304f\u306e\u4fbf\u5229\u306a\u30ea\u30f3\u30bf\u30fc\u3084\u30d5\u30a9\u30fc\u30de\u30c3\u30bf\u30fc\u306e\u4e0a\u306b\u30d5\u30a1\u30b5\u30fc\u30c9\u3092\u63d0\u4f9b\u3059\u308b\u30ea\u30f3\u30c6\u30a3\u30f3\u30b0\u30c4\u30fc\u30eb\u3067\u3059\u3002\u307e\u305f\u3001\u30ea\u30f3\u30bf\u30fc\u3092\u4e26\u5217\u5b9f\u884c\u3057\u3066\u5206\u6790\u901f\u5ea6\u3092\u5411\u4e0a\u3055\u305b\u308b\u3053\u3068\u304c\u3067\u304d\u3001\u975e\u5e38\u306b\u4fbf\u5229\u3067\u3059\u3002
\u30ea\u30f3\u30bf\u30fc\u3068\u30d5\u30a9\u30fc\u30de\u30c3\u30bf\u30fc\u306f\u3001\u30b3\u30fc\u30c9\u30d9\u30fc\u30b9\u306e\u54c1\u8cea\u3068\u4e00\u8cab\u6027\u3092\u5411\u4e0a\u3055\u305b\u308b\u5f37\u529b\u306a\u65b9\u6cd5\u3067\u3059\u3002\u6642\u9593\u3092\u304b\u3051\u3066\u3069\u308c\u3092\u4f7f\u7528\u3059\u3079\u304d\u304b\u3092\u7406\u89e3\u3057\u3001\u305d\u308c\u3089\u306e\u5b9f\u884c\uff08 CI \u3084 Git \u30d7\u30ea\u30b3\u30df\u30c3\u30c8\u30d5\u30c3\u30af\u306a\u3069\uff09\u3092\u81ea\u52d5\u5316\u3057\u307e\u3057\u3087\u3046\u3002
"},{"location":"ja/#_2","title":"\u30c7\u30fc\u30bf\u578b","text":""},{"location":"ja/#8-17","title":"8 \u9032\u6570\u30ea\u30c6\u30e9\u30eb\u3067\u6df7\u4e71\u3092\u62db\u3044\u3066\u3057\u307e\u3046 (#17)","text":"\u8981\u7d04\u65e2\u5b58\u306e\u30b3\u30fc\u30c9\u3092\u8aad\u3080\u3068\u304d\u306f\u3001 0
\u3067\u59cb\u307e\u308b\u6574\u6570\u30ea\u30c6\u30e9\u30eb\u304c 8 \u9032\u6570\u3067\u3042\u308b\u3053\u3068\u306b\u7559\u610f\u3057\u3066\u304f\u3060\u3055\u3044\u3002\u307e\u305f\u3001\u63a5\u982d\u8f9e 0o
\u3092\u4ed8\u3051\u308b\u3053\u3068\u30678\u9032\u6570\u3067\u3042\u308b\u3053\u3068\u3092\u660e\u78ba\u306b\u3057\u3001\u8aad\u307f\u3084\u3059\u3055\u3092\u5411\u4e0a\u3055\u305b\u307e\u3057\u3087\u3046\u3002
8 \u9032\u6570\u306f 0 \u3067\u59cb\u307e\u308a\u307e\u3059\uff08\u305f\u3068\u3048\u3070\u3001010
\u306f 10 \u9032\u6570\u306e 8 \u306b\u76f8\u5f53\u3057\u307e\u3059\uff09\u3002\u53ef\u8aad\u6027\u3092\u5411\u4e0a\u3055\u305b\u3001\u5c06\u6765\u306e\u30b3\u30fc\u30c9\u30ea\u30fc\u30c0\u30fc\u306e\u6f5c\u5728\u7684\u306a\u9593\u9055\u3044\u3092\u56de\u907f\u3059\u308b\u306b\u306f\u3001 0o
\u63a5\u982d\u8f9e\u3092\u4f7f\u7528\u3057\u3066 8 \u9032\u6570\u3067\u3042\u308b\u3053\u3068\u3092\u660e\u3089\u304b\u306b\u3057\u307e\u3057\u3087\u3046\uff08\u4f8b: 0o10
\uff09\u3002
\u4ed6\u306e\u6574\u6570\u30ea\u30c6\u30e9\u30eb\u8868\u73fe\u306b\u3082\u6ce8\u610f\u3057\u3066\u304f\u3060\u3055\u3044\u3002
0b
\u3042\u308b\u3044\u306f 0B
\u3092\u4f7f\u7528\u3057\u307e\u3059\uff08\u305f\u3068\u3048\u3070\u3001 0b
\u306f 10 \u9032\u6570\u306e 4 \u306b\u76f8\u5f53\u3057\u307e\u3059\uff090x
\u3042\u308b\u3044\u306f 0X
\u3092\u4f7f\u7528\u3057\u307e\u3059\uff08\u305f\u3068\u3048\u3070\u3001 0xF
\u306f 10 \u9032\u6570\u306e 15 \u306b\u76f8\u5f53\u3057\u307e\u3059\uff09\u3002 i
\u3092\u4f7f\u7528\u3057\u307e\u3059\uff08\u305f\u3068\u3048\u3070\u3001 3i
\uff09\u8aad\u307f\u3084\u3059\u304f\u3059\u308b\u305f\u3081\u306b\u3001\u533a\u5207\u308a\u6587\u5b57\u3068\u3057\u3066\u30a2\u30f3\u30c0\u30fc\u30b9\u30b3\u30a2\uff08 _ \uff09\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u3082\u3067\u304d\u307e\u3059\u3002\u305f\u3068\u3048\u3070\u3001 10 \u5104\u306f 1_000_000_000
\u306e\u3088\u3046\u306b\u66f8\u304f\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u30a2\u30f3\u30c0\u30fc\u30b9\u30b3\u30a2\u306f 0b)00_00_01
\u306e\u3088\u3046\u306b\u4ed6\u306e\u8868\u73fe\u3068\u4f75\u7528\u3059\u308b\u3053\u3068\u3082\u3067\u304d\u307e\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#18","title":"\u6574\u6570\u30aa\u30fc\u30d0\u30fc\u30d5\u30ed\u30fc\u3092\u7121\u8996\u3057\u3066\u3044\u308b (#18)","text":"\u8981\u7d04Go\u8a00\u8a9e\u3067\u306f\u6574\u6570\u306e\u30aa\u30fc\u30d0\u30fc\u30d5\u30ed\u30fc\u3068\u30a2\u30f3\u30c0\u30fc\u30d5\u30ed\u30fc\u304c\u88cf\u5074\u3067\u51e6\u7406\u3055\u308c\u308b\u305f\u3081\u3001\u305d\u308c\u3089\u3092\u30ad\u30e3\u30c3\u30c1\u3059\u308b\u72ec\u81ea\u306e\u95a2\u6570\u3092\u5b9f\u88c5\u3067\u304d\u307e\u3059\u3002
Go\u8a00\u8a9e\u3067\u306f\u3001\u30b3\u30f3\u30d1\u30a4\u30eb\u6642\u306b\u691c\u51fa\u3067\u304d\u308b\u6574\u6570\u30aa\u30fc\u30d0\u30fc\u30d5\u30ed\u30fc\u306b\u3088\u3063\u3066\u30b3\u30f3\u30d1\u30a4\u30eb\u30a8\u30e9\u30fc\u304c\u751f\u6210\u3055\u308c\u307e\u3059\u3002\u305f\u3068\u3048\u3070\u3001\u6b21\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002
var counter int32 = math.MaxInt32 + 1\n
constant 2147483648 overflows int32\n
\u305f\u3060\u3057\u3001\u5b9f\u884c\u6642\u306b\u306f\u3001\u6574\u6570\u306e\u30aa\u30fc\u30d0\u30fc\u30d5\u30ed\u30fc\u307e\u305f\u306f\u30a2\u30f3\u30c0\u30fc\u30d5\u30ed\u30fc\u306f\u767a\u751f\u3057\u307e\u305b\u3093\u3002\u3053\u308c\u306b\u3088\u3063\u3066\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u30d1\u30cb\u30c3\u30af\u304c\u767a\u751f\u3059\u308b\u3053\u3068\u306f\u3042\u308a\u307e\u305b\u3093\u3002\u3053\u306e\u52d5\u4f5c\u306f\u3084\u3063\u304b\u3044\u306a\u30d0\u30b0\uff08\u305f\u3068\u3048\u3070\u3001\u8ca0\u306e\u7d50\u679c\u306b\u3064\u306a\u304c\u308b\u6574\u6570\u306e\u5897\u5206\u3084\u6b63\u306e\u6574\u6570\u306e\u52a0\u7b97\u306a\u3069\uff09\u306b\u3064\u306a\u304c\u308b\u53ef\u80fd\u6027\u304c\u3042\u308b\u305f\u3081\u3001\u982d\u306b\u5165\u308c\u3066\u304a\u304f\u3053\u3068\u304c\u91cd\u8981\u3067\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#19","title":"\u6d6e\u52d5\u5c0f\u6570\u70b9\u3092\u7406\u89e3\u3057\u3066\u3044\u306a\u3044 (#19)","text":"\u8981\u7d04\u7279\u5b9a\u306e\u30c7\u30eb\u30bf\u5185\u3067\u6d6e\u52d5\u5c0f\u6570\u70b9\u6bd4\u8f03\u3092\u884c\u3046\u3068\u3001\u30b3\u30fc\u30c9\u306e\u79fb\u690d\u6027\u3092\u78ba\u4fdd\u3067\u304d\u307e\u3059\u3002\u52a0\u7b97\u307e\u305f\u306f\u6e1b\u7b97\u3092\u5b9f\u884c\u3059\u308b\u3068\u304d\u306f\u3001\u7cbe\u5ea6\u3092\u5411\u4e0a\u3055\u305b\u308b\u305f\u3081\u306b\u3001\u540c\u7a0b\u5ea6\u306e\u5927\u304d\u3055\u306e\u6f14\u7b97\u3092\u30b0\u30eb\u30fc\u30d7\u5316\u3057\u3066\u304f\u3060\u3055\u3044\u3002\u307e\u305f\u3001\u4e57\u7b97\u3068\u9664\u7b97\u306f\u52a0\u7b97\u3068\u6e1b\u7b97\u306e\u524d\u306b\u5b9f\u884c\u3057\u3066\u304f\u3060\u3055\u3044\u3002
Go\u8a00\u8a9e\u306b\u306f\u3001\uff08\u865a\u6570\u3092\u9664\u3044\u305f\u5834\u5408\uff09 float32
\u3068 float64
\u3068\u3044\u3046 2 \u3064\u306e\u6d6e\u52d5\u5c0f\u6570\u70b9\u578b\u304c\u3042\u308a\u307e\u3059\u3002\u6d6e\u52d5\u5c0f\u6570\u70b9\u306e\u6982\u5ff5\u306f\u3001\u5c0f\u6570\u5024\u3092\u8868\u73fe\u3067\u304d\u306a\u3044\u3068\u3044\u3046\u6574\u6570\u306e\u5927\u304d\u306a\u554f\u984c\u3092\u89e3\u6c7a\u3059\u308b\u305f\u3081\u306b\u767a\u660e\u3055\u308c\u307e\u3057\u305f\u3002\u4e88\u60f3\u5916\u306e\u4e8b\u614b\u3092\u907f\u3051\u308b\u305f\u3081\u306b\u3001\u6d6e\u52d5\u5c0f\u6570\u70b9\u6f14\u7b97\u306f\u5b9f\u969b\u306e\u6f14\u7b97\u306e\u8fd1\u4f3c\u3067\u3042\u308b\u3053\u3068\u3092\u77e5\u3063\u3066\u304a\u304f\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002
\u305d\u306e\u305f\u3081\u306b\u3001\u4e57\u7b97\u306e\u4f8b\u3092\u898b\u3066\u307f\u307e\u3057\u3087\u3046\u3002
var n float32 = 1.0001\nfmt.Println(n * n)\n
\u3053\u306e\u30b3\u30fc\u30c9\u306b\u304a\u3044\u3066\u306f 1.0001 * 1.0001 = 1.00020001 \u3068\u3044\u3046\u7d50\u679c\u304c\u51fa\u529b\u3055\u308c\u308b\u3053\u3068\u3092\u671f\u5f85\u3059\u308b\u3068\u601d\u3044\u307e\u3059\u3002\u3057\u304b\u3057\u306a\u304c\u3089\u3001\u307b\u3068\u3093\u3069\u306e x86 \u30d7\u30ed\u30bb\u30c3\u30b5\u3067\u306f\u3001\u4ee3\u308f\u308a\u306b 1.0002 \u304c\u51fa\u529b\u3055\u308c\u307e\u3059\u3002
Go\u8a00\u8a9e\u306e float32
\u304a\u3088\u3073 float64
\u578b\u306f\u8fd1\u4f3c\u5024\u3067\u3042\u308b\u305f\u3081\u3001\u3044\u304f\u3064\u304b\u306e\u30eb\u30fc\u30eb\u3092\u5ff5\u982d\u306b\u7f6e\u304f\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#20","title":"\u30b9\u30e9\u30a4\u30b9\u306e\u9577\u3055\u3068\u5bb9\u91cf\u3092\u7406\u89e3\u3057\u3066\u3044\u306a\u3044 (#20)","text":"\u8981\u7d04Go \u958b\u767a\u8005\u306a\u3089\u3070\u3001\u30b9\u30e9\u30a4\u30b9\u306e\u9577\u3055\u3068\u5bb9\u91cf\u306e\u9055\u3044\u3092\u7406\u89e3\u3059\u308b\u3079\u304d\u3067\u3059\u3002\u30b9\u30e9\u30a4\u30b9\u306e\u9577\u3055\u306f\u30b9\u30e9\u30a4\u30b9\u5185\u306e\u4f7f\u7528\u53ef\u80fd\u306a\u8981\u7d20\u306e\u6570\u3067\u3042\u308a\u3001\u30b9\u30e9\u30a4\u30b9\u306e\u5bb9\u91cf\u306f\u30d0\u30c3\u30ad\u30f3\u30b0\u914d\u5217\u5185\u306e\u8981\u7d20\u306e\u6570\u3067\u3059\u3002
\u30bb\u30af\u30b7\u30e7\u30f3\u5168\u6587\u306f\u3053\u3061\u3089\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#21","title":"\u975e\u52b9\u7387\u306a\u30b9\u30e9\u30a4\u30b9\u306e\u521d\u671f\u5316 (#21)","text":"\u8981\u7d04\u30b9\u30e9\u30a4\u30b9\u3092\u4f5c\u6210\u3059\u308b\u3068\u304d\u3001\u9577\u3055\u304c\u3059\u3067\u306b\u308f\u304b\u3063\u3066\u3044\u308b\u5834\u5408\u306f\u3001\u6307\u5b9a\u3055\u308c\u305f\u9577\u3055\u307e\u305f\u306f\u5bb9\u91cf\u3067\u30b9\u30e9\u30a4\u30b9\u3092\u521d\u671f\u5316\u3057\u307e\u3057\u3087\u3046\u3002\u3053\u308c\u306b\u3088\u308a\u3001\u5272\u308a\u5f53\u3066\u306e\u6570\u304c\u6e1b\u308a\u3001\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u304c\u5411\u4e0a\u3057\u307e\u3059\u3002
make
\u3092\u4f7f\u7528\u3057\u3066\u30b9\u30e9\u30a4\u30b9\u3092\u521d\u671f\u5316\u3059\u308b\u3068\u304d\u306b\u3001\u9577\u3055\u3068\u30aa\u30d7\u30b7\u30e7\u30f3\u306e\u5bb9\u91cf\u3092\u6307\u5b9a\u3067\u304d\u307e\u3059\u3002\u3053\u308c\u3089\u306e\u30d1\u30e9\u30e1\u30fc\u30bf\u306e\u4e21\u65b9\u306b\u9069\u5207\u306a\u5024\u3092\u6e21\u3059\u3053\u3068\u304c\u9069\u5f53\u3067\u3042\u308b\u306b\u3082\u304b\u304b\u308f\u3089\u305a\u3001\u305d\u308c\u3092\u5fd8\u308c\u308b\u306e\u306f\u3088\u304f\u3042\u308b\u9593\u9055\u3044\u3067\u3059\u3002\u5b9f\u969b\u3001\u8907\u6570\u306e\u30b3\u30d4\u30fc\u304c\u5fc5\u8981\u306b\u306a\u308a\u3001\u4e00\u6642\u7684\u306a\u30d0\u30c3\u30ad\u30f3\u30b0\u914d\u5217\u3092\u30af\u30ea\u30fc\u30f3\u30a2\u30c3\u30d7\u3059\u308b\u305f\u3081\u306b GC \u306b\u8ffd\u52a0\u306e\u52b4\u529b\u304c\u304b\u304b\u308b\u53ef\u80fd\u6027\u304c\u3042\u308a\u307e\u3059\u3002\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u306e\u89b3\u70b9\u304b\u3089\u8a00\u3048\u3070\u3001Go \u30e9\u30f3\u30bf\u30a4\u30e0\u306b\u624b\u3092\u5dee\u3057\u4f38\u3079\u306a\u3044\u7406\u7531\u306f\u3042\u308a\u307e\u305b\u3093\u3002
\u30aa\u30d7\u30b7\u30e7\u30f3\u306f\u3001\u6307\u5b9a\u3055\u308c\u305f\u5bb9\u91cf\u307e\u305f\u306f\u6307\u5b9a\u3055\u308c\u305f\u9577\u3055\u306e\u30b9\u30e9\u30a4\u30b9\u3092\u5272\u308a\u5f53\u3066\u308b\u3053\u3068\u3067\u3059\u3002 \u3053\u308c\u3089 2 \u3064\u306e\u89e3\u6c7a\u7b56\u306e\u3046\u3061\u30012 \u756a\u76ee\u306e\u89e3\u6c7a\u7b56\u306e\u65b9\u304c\u308f\u305a\u304b\u306b\u9ad8\u901f\u3067\u3042\u308b\u50be\u5411\u304c\u3042\u308b\u3053\u3068\u304c\u308f\u304b\u308a\u307e\u3057\u305f\u3002\u305f\u3060\u3057\u3001\u7279\u5b9a\u306e\u5bb9\u91cf\u3068\u8ffd\u52a0\u3092\u4f7f\u7528\u3059\u308b\u3068\u3001\u5834\u5408\u306b\u3088\u3063\u3066\u306f\u5b9f\u88c5\u3068\u8aad\u307f\u53d6\u308a\u304c\u5bb9\u6613\u306b\u306a\u308b\u3053\u3068\u304c\u3042\u308a\u307e\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#nil-22","title":"nil \u3068\u7a7a\u306e\u30b9\u30e9\u30a4\u30b9\u3092\u6df7\u540c\u3057\u3066\u3044\u308b (#22)","text":"\u8981\u7d04encoding/json
\u3084 reflect
\u30d1\u30c3\u30b1\u30fc\u30b8\u306a\u3069\u3092\u4f7f\u7528\u3059\u308b\u3068\u304d\u306b\u3088\u304f\u3042\u308b\u6df7\u4e71\u3092\u907f\u3051\u308b\u305f\u3081\u306b\u306f\u3001nil \u30b9\u30e9\u30a4\u30b9\u3068\u7a7a\u306e\u30b9\u30e9\u30a4\u30b9\u306e\u9055\u3044\u3092\u7406\u89e3\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u3069\u3061\u3089\u3082\u9577\u3055\u30bc\u30ed\u3001\u5bb9\u91cf\u30bc\u30ed\u306e\u30b9\u30e9\u30a4\u30b9\u3067\u3059\u304c\u3001\u5272\u308a\u5f53\u3066\u3092\u5fc5\u8981\u3068\u3057\u306a\u3044\u306e\u306f nil \u30b9\u30e9\u30a4\u30b9\u3060\u3051\u3067\u3059\u3002
Go\u8a00\u8a9e\u3067\u306f\u3001nil \u3068\u7a7a\u306e\u30b9\u30e9\u30a4\u30b9\u306f\u533a\u5225\u3055\u308c\u307e\u3059\u3002nil \u30b9\u30e9\u30a4\u30b9\u306f nil
\u306b\u7b49\u3057\u3044\u306e\u306b\u5bfe\u3057\u3001\u7a7a\u306e\u30b9\u30e9\u30a4\u30b9\u306e\u9577\u3055\u306f\u30bc\u30ed\u3067\u3059\u3002nil \u30b9\u30e9\u30a4\u30b9\u306f\u7a7a\u3067\u3059\u304c\u3001\u7a7a\u306e\u30b9\u30e9\u30a4\u30b9\u306f\u5fc5\u305a\u3057\u3082nil
\u3067\u3042\u308b\u3068\u306f\u9650\u308a\u307e\u305b\u3093\u3002\u4e00\u65b9\u3001nil \u30b9\u30e9\u30a4\u30b9\u306b\u306f\u5272\u308a\u5f53\u3066\u306f\u5fc5\u8981\u3042\u308a\u307e\u305b\u3093\u3002\u3053\u306e\u30bb\u30af\u30b7\u30e7\u30f3\u5168\u4f53\u3092\u901a\u3057\u3066\u3001\u4ee5\u4e0b\u306e\u65b9\u6cd5\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u306b\u3088\u3063\u3066\u3001\u72b6\u6cc1\u306b\u5fdc\u3058\u3066\u30b9\u30e9\u30a4\u30b9\u3092\u521d\u671f\u5316\u3059\u308b\u3053\u3068\u3092\u898b\u3066\u304d\u307e\u3057\u305f\u3002
var s []string
[]string(nil)
make([]string, length)
\u8981\u7d20\u306a\u3057\u3067\u30b9\u30e9\u30a4\u30b9\u3092\u521d\u671f\u5316\u3059\u308b\u5834\u5408\u3001\u6700\u5f8c\u306e\u30aa\u30d7\u30b7\u30e7\u30f3 []string{}
\u306f\u907f\u3051\u308b\u3079\u304d\u3067\u3059\u3002\u6700\u5f8c\u306b\u3001\u4e88\u60f3\u5916\u306e\u52d5\u4f5c\u3092\u9632\u3050\u305f\u3081\u306b\u3001\u4f7f\u7528\u3059\u308b\u30e9\u30a4\u30d6\u30e9\u30ea\u304c nil \u3068\u7a7a\u306e\u30b9\u30e9\u30a4\u30b9\u3092\u533a\u5225\u3057\u3066\u3044\u308b\u304b\u3069\u3046\u304b\u3092\u78ba\u8a8d\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#23","title":"\u30b9\u30e9\u30a4\u30b9\u304c\u7a7a\u304b\u3069\u3046\u304b\u3092\u9069\u5207\u306b\u78ba\u8a8d\u3057\u306a\u3044 (#23)","text":"\u8981\u7d04\u30b9\u30e9\u30a4\u30b9\u306b\u8981\u7d20\u304c\u542b\u307e\u308c\u3066\u3044\u306a\u3044\u3053\u3068\u3092\u78ba\u8a8d\u3059\u308b\u306b\u306f\u3001\u305d\u306e\u9577\u3055\u3092\u78ba\u8a8d\u3057\u307e\u3057\u3087\u3046\u3002\u3053\u308c\u306f\u3001\u30b9\u30e9\u30a4\u30b9\u304c nil
\u3067\u3042\u308b\u304b\u7a7a\u3067\u3042\u308b\u304b\u306b\u95a2\u4fc2\u306a\u304f\u6a5f\u80fd\u3057\u307e\u3059\u3002\u30de\u30c3\u30d7\u306b\u3064\u3044\u3066\u3082\u540c\u69d8\u3067\u3059\u3002\u660e\u78ba\u306a API \u3092\u8a2d\u8a08\u3059\u308b\u306b\u306f\u3001nil \u30b9\u30e9\u30a4\u30b9\u3068\u7a7a\u306e\u30b9\u30e9\u30a4\u30b9\u3092\u533a\u5225\u3057\u306a\u3044\u3067\u304f\u3060\u3055\u3044\u3002
\u30b9\u30e9\u30a4\u30b9\u306b\u8981\u7d20\u304c\u3042\u308b\u304b\u3069\u3046\u304b\u3092\u5224\u65ad\u3059\u308b\u306b\u306f\u3001\u30b9\u30e9\u30a4\u30b9\u304c nil \u304b\u3069\u3046\u304b\u3001\u307e\u305f\u306f\u305d\u306e\u9577\u3055\u304c 0 \u306b\u7b49\u3057\u3044\u304b\u3069\u3046\u304b\u3092\u78ba\u8a8d\u3059\u308b\u3053\u3068\u3067\u5224\u65ad\u3067\u304d\u307e\u3059\u3002\u30b9\u30e9\u30a4\u30b9\u304c\u7a7a\u3067\u3042\u308b\u5834\u5408\u3068\u30b9\u30e9\u30a4\u30b9\u304c nil \u3067\u3042\u308b\u5834\u5408\u306e\u4e21\u65b9\u3092\u30ab\u30d0\u30fc\u3067\u304d\u308b\u305f\u3081\u3001\u9577\u3055\u3092\u78ba\u304b\u3081\u308b\u3053\u3068\u304c\u6700\u826f\u306e\u65b9\u6cd5\u3067\u3059\u3002
\u4e00\u65b9\u3001\u30a4\u30f3\u30bf\u30d5\u30a7\u30fc\u30b9\u3092\u8a2d\u8a08\u3059\u308b\u3068\u304d\u306f\u3001\u8efd\u5fae\u306a\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u30a8\u30e9\u30fc\u3092\u8d77\u3053\u3055\u306a\u3044\u3088\u3046 nil \u30b9\u30e9\u30a4\u30b9\u3068\u7a7a\u306e\u30b9\u30e9\u30a4\u30b9\u3092\u533a\u5225\u3057\u306a\u3044\u3088\u3046\u306b\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u30b9\u30e9\u30a4\u30b9\u3092\u8fd4\u3059\u3068\u304d\u306b\u3001nil \u307e\u305f\u306f\u7a7a\u306e\u30b9\u30e9\u30a4\u30b9\u3092\u8fd4\u3059\u304b\u3069\u3046\u304b\u306f\u3001\u610f\u5473\u7684\u306b\u3082\u6280\u8853\u7684\u306b\u3082\u9055\u3044\u306f\u3042\u308a\u307e\u305b\u3093\u3002\u30b3\u30fc\u30e9\u30fc\u306b\u3068\u3063\u3066\u306f\u3069\u3061\u3089\u3082\u540c\u3058\u3053\u3068\u3092\u610f\u5473\u3059\u308b\u306f\u305a\u3067\u3059\u3002\u3053\u306e\u539f\u7406\u306f\u30de\u30c3\u30d7\u3067\u3082\u540c\u3058\u3067\u3059\u3002\u30de\u30c3\u30d7\u304c\u7a7a\u304b\u3069\u3046\u304b\u3092\u78ba\u8a8d\u3059\u308b\u306b\u306f\u3001\u305d\u308c\u304c nil \u304b\u3069\u3046\u304b\u3067\u306f\u306a\u304f\u3001\u305d\u306e\u9577\u3055\u3092\u78ba\u8a8d\u3057\u307e\u3057\u3087\u3046\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#24","title":"\u30b9\u30e9\u30a4\u30b9\u306e\u30b3\u30d4\u30fc\u3092\u6b63\u3057\u304f\u4f5c\u6210\u3057\u3066\u3044\u306a\u3044 (#24)","text":"\u8981\u7d04\u7d44\u307f\u8fbc\u307f\u95a2\u6570 copy
\u3092\u4f7f\u7528\u3057\u3066\u3042\u308b\u30b9\u30e9\u30a4\u30b9\u3092\u5225\u306e\u30b9\u30e9\u30a4\u30b9\u306b\u30b3\u30d4\u30fc\u3059\u308b\u306b\u306f\u3001\u30b3\u30d4\u30fc\u3055\u308c\u308b\u8981\u7d20\u306e\u6570\u304c 2 \u3064\u306e\u30b9\u30e9\u30a4\u30b9\u306e\u9577\u3055\u306e\u9593\u306e\u6700\u5c0f\u5024\u306b\u76f8\u5f53\u3059\u308b\u3053\u3068\u306b\u6ce8\u610f\u3057\u3066\u304f\u3060\u3055\u3044\u3002
\u8981\u7d20\u3092\u3042\u308b\u30b9\u30e9\u30a4\u30b9\u304b\u3089\u5225\u306e\u30b9\u30e9\u30a4\u30b9\u306b\u30b3\u30d4\u30fc\u3059\u308b\u64cd\u4f5c\u306f\u3001\u304b\u306a\u308a\u983b\u7e41\u306b\u884c\u308f\u308c\u307e\u3059\u3002\u30b3\u30d4\u30fc\u3092\u4f7f\u7528\u3059\u308b\u5834\u5408\u3001\u30b3\u30d4\u30fc\u5148\u306b\u30b3\u30d4\u30fc\u3055\u308c\u308b\u8981\u7d20\u306e\u6570\u306f 2 \u3064\u306e\u30b9\u30e9\u30a4\u30b9\u306e\u9577\u3055\u306e\u9593\u306e\u6700\u5c0f\u5024\u306b\u76f8\u5f53\u3059\u308b\u3053\u3068\u306b\u6ce8\u610f\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u307e\u305f\u3001\u30b9\u30e9\u30a4\u30b9\u3092\u30b3\u30d4\u30fc\u3059\u308b\u305f\u3081\u306e\u4ed6\u306e\u4ee3\u66ff\u624b\u6bb5\u304c\u5b58\u5728\u3059\u308b\u3053\u3068\u306b\u3082\u7559\u610f\u3057\u3066\u304f\u3060\u3055\u3044\u3002\u305d\u306e\u305f\u3081\u3001\u30b3\u30fc\u30c9\u30d9\u30fc\u30b9\u3067\u305d\u308c\u3089\u3092\u898b\u3064\u3051\u3066\u3082\u9a5a\u304f\u3053\u3068\u306f\u3042\u308a\u307e\u305b\u3093\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#append-25","title":"append
\u306e\u4f7f\u7528\u306b\u3088\u308b\u4e88\u60f3\u5916\u306e\u526f\u4f5c\u7528 (#25)","text":"\u8981\u7d04 2\u3064\u306e\u7570\u306a\u308b\u95a2\u6570\u304c\u540c\u3058\u914d\u5217\u306b\u57fa\u3065\u304f\u30b9\u30e9\u30a4\u30b9\u3092\u4f7f\u7528\u3059\u308b\u5834\u5408\u306b\u3001copy \u307e\u305f\u306f\u5b8c\u5168\u30b9\u30e9\u30a4\u30b9\u5f0f\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u3067 append
\u306b\u3088\u308b\u885d\u7a81\u3092\u9632\u3050\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u305f\u3060\u3057\u3001\u5927\u304d\u306a\u30b9\u30e9\u30a4\u30b9\u3092\u7e2e\u5c0f\u3059\u308b\u5834\u5408\u3001\u30e1\u30e2\u30ea\u30ea\u30fc\u30af\u3092\u9632\u3050\u3053\u3068\u304c\u3067\u304d\u308b\u306e\u306f\u30b9\u30e9\u30a4\u30b9\u306e\u30b3\u30d4\u30fc\u3060\u3051\u3067\u3059\u3002
\u30b9\u30e9\u30a4\u30b9\u3092\u4f7f\u7528\u3059\u308b\u3068\u304d\u306f\u3001\u4e88\u60f3\u5916\u306e\u526f\u4f5c\u7528\u306b\u3064\u306a\u304c\u308b\u72b6\u6cc1\u306b\u76f4\u9762\u3059\u308b\u53ef\u80fd\u6027\u304c\u3042\u308b\u3053\u3068\u3092\u899a\u3048\u3066\u304a\u304f\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u7d50\u679c\u306e\u30b9\u30e9\u30a4\u30b9\u306e\u9577\u3055\u304c\u305d\u306e\u5bb9\u91cf\u3088\u308a\u5c0f\u3055\u3044\u5834\u5408\u3001\u8ffd\u52a0\u306b\u3088\u3063\u3066\u5143\u306e\u30b9\u30e9\u30a4\u30b9\u304c\u5909\u66f4\u3055\u308c\u308b\u53ef\u80fd\u6027\u304c\u3042\u308a\u307e\u3059\u3002\u8d77\u3053\u308a\u5f97\u308b\u526f\u4f5c\u7528\u306e\u7bc4\u56f2\u3092\u5236\u9650\u3057\u305f\u3044\u5834\u5408\u306f\u3001\u30b9\u30e9\u30a4\u30b9\u306e\u30b3\u30d4\u30fc\u307e\u305f\u306f\u5b8c\u5168\u30b9\u30e9\u30a4\u30b9\u5f0f\u3092\u4f7f\u7528\u3067\u304d\u307e\u3059\u3002\u3053\u308c\u306b\u3088\u308a\u3001\u30b3\u30d4\u30fc\u3092\u5b9f\u884c\u3067\u304d\u306a\u304f\u306a\u308a\u307e\u3059\u3002
\u88dc\u8db3s[low:high:max]
\uff08\u5b8c\u5168\u30b9\u30e9\u30a4\u30b9\u5f0f\uff09\u2015\u2015\u3053\u306e\u547d\u4ee4\u6587\u306f\u3001\u5bb9\u91cf\u304c max - low
\u306b\u7b49\u3057\u3044\u3053\u3068\u3092\u9664\u3051\u3070\u3001s[low:high]
\u3067\u4f5c\u6210\u3055\u308c\u305f\u30b9\u30e9\u30a4\u30b9\u3068\u540c\u69d8\u306e\u30b9\u30e9\u30a4\u30b9\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#26","title":"\u30b9\u30e9\u30a4\u30b9\u3068\u30e1\u30e2\u30ea\u30ea\u30fc\u30af (#26)","text":"\u8981\u7d04\u30dd\u30a4\u30f3\u30bf\u306e\u30b9\u30e9\u30a4\u30b9\u307e\u305f\u306f\u30dd\u30a4\u30f3\u30bf\u30d5\u30a3\u30fc\u30eb\u30c9\u3092\u6301\u3064\u69cb\u9020\u4f53\u3092\u64cd\u4f5c\u3059\u308b\u5834\u5408\u3001\u30b9\u30e9\u30a4\u30b9\u64cd\u4f5c\u306b\u3088\u3063\u3066\u9664\u5916\u3055\u308c\u305f\u8981\u7d20\u3092 nil \u3068\u3059\u308b\u3053\u3068\u3067\u30e1\u30e2\u30ea\u30ea\u30fc\u30af\u3092\u56de\u907f\u3067\u304d\u307e\u3059\u3002
"},{"location":"ja/#_3","title":"\u5bb9\u91cf\u6f0f\u308c","text":"\u5927\u304d\u306a\u30b9\u30e9\u30a4\u30b9\u307e\u305f\u306f\u914d\u5217\u3092\u30b9\u30e9\u30a4\u30b9\u3059\u308b\u3068\u3001\u30e1\u30e2\u30ea\u6d88\u8cbb\u304c\u9ad8\u304f\u306a\u308b\u53ef\u80fd\u6027\u304c\u3042\u308b\u3053\u3068\u306b\u6ce8\u610f\u3057\u3066\u304f\u3060\u3055\u3044\u3002\u6b8b\u308a\u306e\u30b9\u30da\u30fc\u30b9\u306f GC \u306b\u3088\u3063\u3066\u518d\u5229\u7528\u3055\u308c\u305a\u3001\u5c11\u6570\u306e\u8981\u7d20\u3057\u304b\u4f7f\u7528\u3057\u306a\u3044\u306b\u3082\u304b\u304b\u308f\u3089\u305a\u3001\u5927\u304d\u306a\u30d0\u30c3\u30ad\u30f3\u30b0\u914d\u5217\u304c\u4fdd\u6301\u3055\u308c\u307e\u3059\u3002\u30b9\u30e9\u30a4\u30b9\u306e\u30b3\u30d4\u30fc\u3092\u3059\u308b\u3053\u3068\u3067\u3001\u3053\u306e\u3088\u3046\u306a\u4e8b\u614b\u3092\u9632\u3050\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#_4","title":"\u30b9\u30e9\u30a4\u30b9\u3068\u30dd\u30a4\u30f3\u30bf","text":"\u30dd\u30a4\u30f3\u30bf\u307e\u305f\u306f\u30dd\u30a4\u30f3\u30bf\u30d5\u30a3\u30fc\u30eb\u30c9\u3092\u542b\u3080\u69cb\u9020\u4f53\u3092\u4f7f\u7528\u3057\u3066\u30b9\u30e9\u30a4\u30b9\u64cd\u4f5c\u3092\u3059\u308b\u5834\u5408\u3001GC \u304c\u3053\u308c\u3089\u306e\u8981\u7d20\u3092\u518d\u5229\u7528\u3057\u306a\u3044\u3053\u3068\u3092\u77e5\u3063\u3066\u304a\u304f\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u305d\u306e\u5834\u5408\u306e\u9078\u629e\u80a2\u306f\u3001\u30b3\u30d4\u30fc\u3092\u5b9f\u884c\u3059\u308b\u304b\u3001\u6b8b\u308a\u306e\u8981\u7d20\u307e\u305f\u306f\u305d\u306e\u30d5\u30a3\u30fc\u30eb\u30c9\u3092\u660e\u793a\u7684\u306b nil
\u3068\u3059\u308b\u3053\u3068\u3067\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#27","title":"\u975e\u52b9\u7387\u306a\u30de\u30c3\u30d7\u306e\u521d\u671f\u5316 (#27)","text":"\u8981\u7d04\u30de\u30c3\u30d7\u3092\u4f5c\u6210\u3059\u308b\u3068\u304d\u3001\u305d\u306e\u9577\u3055\u304c\u3059\u3067\u306b\u308f\u304b\u3063\u3066\u3044\u308b\u5834\u5408\u306f\u3001\u6307\u5b9a\u3055\u308c\u305f\u9577\u3055\u3067\u521d\u671f\u5316\u3057\u307e\u3059\u3002\u3053\u308c\u306b\u3088\u308a\u3001\u5272\u308a\u5f53\u3066\u306e\u6570\u304c\u6e1b\u308a\u3001\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u304c\u5411\u4e0a\u3057\u307e\u3059\u3002
\u30de\u30c3\u30d7\u306f\u3001\u30ad\u30fc\u30fb\u5024\u30da\u30a2\u306e\u9806\u5e8f\u306a\u3057\u30b3\u30ec\u30af\u30b7\u30e7\u30f3\u3092\u63d0\u4f9b\u3057\u307e\u3059\u3002\u306a\u304a\u3001\u305d\u308c\u305e\u308c\u306e\u30da\u30a2\u306f\u56fa\u6709\u306e\u30ad\u30fc\u3092\u6301\u3061\u307e\u3059\u3002Go\u8a00\u8a9e\u3067\u306f\u3001\u30de\u30c3\u30d7\u306f\u30cf\u30c3\u30b7\u30e5\u30c6\u30fc\u30d6\u30eb\u30c7\u30fc\u30bf\u69cb\u9020\u306b\u57fa\u3065\u3044\u3066\u3044\u307e\u3059\u3002\u5185\u90e8\u7684\u306b\u306f\u3001\u30cf\u30c3\u30b7\u30e5\u30c6\u30fc\u30d6\u30eb\u306f\u30d0\u30b1\u30c3\u30c8\u306e\u914d\u5217\u3067\u3042\u308a\u3001\u5404\u30d0\u30b1\u30c3\u30c8\u306f\u30ad\u30fc\u30fb\u5024\u30da\u30a2\u306e\u914d\u5217\u3078\u306e\u30dd\u30a4\u30f3\u30bf\u3067\u3059\u3002
\u30de\u30c3\u30d7\u306b\u542b\u307e\u308c\u308b\u8981\u7d20\u306e\u6570\u304c\u4e8b\u524d\u306b\u308f\u304b\u3063\u3066\u3044\u308b\u5834\u5408\u306f\u3001\u305d\u306e\u521d\u671f\u30b5\u30a4\u30ba\u3092\u6307\u5b9a\u3057\u3066\u4f5c\u6210\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u30de\u30c3\u30d7\u306e\u5897\u5927\u306f\u3001\u5341\u5206\u306a\u30b9\u30da\u30fc\u30b9\u3092\u518d\u5272\u308a\u5f53\u3066\u3057\u3001\u3059\u3079\u3066\u306e\u8981\u7d20\u306e\u30d0\u30e9\u30f3\u30b9\u3092\u518d\u8abf\u6574\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u305f\u3081\u3001\u8a08\u7b97\u91cf\u304c\u975e\u5e38\u306b\u591a\u304f\u306a\u308a\u307e\u3059\u304c\u3001\u3053\u308c\u306b\u3088\u308a\u305d\u308c\u3092\u56de\u907f\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#28","title":"\u30de\u30c3\u30d7\u3068\u30e1\u30e2\u30ea\u30ea\u30fc\u30af (#28)","text":"\u8981\u7d04\u30de\u30c3\u30d7\u306f\u30e1\u30e2\u30ea\u5185\u3067\u5e38\u306b\u5897\u5927\u3059\u308b\u53ef\u80fd\u6027\u304c\u3042\u308a\u307e\u3059\u304c\u3001\u7e2e\u5c0f\u3059\u308b\u3053\u3068\u306f\u3042\u308a\u307e\u305b\u3093\u3002\u3057\u305f\u304c\u3063\u3066\u3001\u30e1\u30e2\u30ea\u306e\u554f\u984c\u304c\u767a\u751f\u3059\u308b\u5834\u5408\u306f\u3001\u30de\u30c3\u30d7\u3092\u5f37\u5236\u7684\u306b\u518d\u751f\u6210\u3057\u305f\u308a\u3001\u30dd\u30a4\u30f3\u30bf\u3092\u4f7f\u7528\u3057\u305f\u308a\u3059\u308b\u306a\u3069\u3001\u3055\u307e\u3056\u307e\u306a\u624b\u6bb5\u3092\u8a66\u3059\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002
\u30bb\u30af\u30b7\u30e7\u30f3\u5168\u6587\u306f\u3053\u3061\u3089\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#29","title":"\u8aa4\u3063\u305f\u65b9\u6cd5\u306b\u3088\u308b\u5024\u306e\u6bd4\u8f03 (#29)","text":"\u8981\u7d04Go\u8a00\u8a9e\u3067\u578b\u3092\u6bd4\u8f03\u3059\u200b\u200b\u308b\u306b\u306f\u30012 \u3064\u306e\u578b\u304c\u6bd4\u8f03\u53ef\u80fd\u306a\u3089\u3070\u3001== \u6f14\u7b97\u5b50\u3068 != \u6f14\u7b97\u5b50\u3092\u4f7f\u7528\u3067\u304d\u307e\u3059\u3002\u771f\u507d\u5024\u3001\u6570\u5024\u3001\u6587\u5b57\u5217\u3001\u30dd\u30a4\u30f3\u30bf\u3001\u30c1\u30e3\u30cd\u30eb\u3001\u304a\u3088\u3073\u69cb\u9020\u4f53\u304c\u5b8c\u5168\u306b\u6bd4\u8f03\u53ef\u80fd\u306a\u578b\u3067\u69cb\u6210\u3055\u308c\u3066\u3044\u307e\u3059\u3002\u305d\u308c\u4ee5\u5916\u306f\u3001 reflect.DeepEqual
\u3092\u4f7f\u7528\u3057\u3066\u30ea\u30d5\u30ec\u30af\u30b7\u30e7\u30f3\u306e\u4ee3\u511f\u3092\u652f\u6255\u3046\u304b\u3001\u72ec\u81ea\u306e\u5b9f\u88c5\u3068\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002
\u52b9\u679c\u7684\u306b\u6bd4\u8f03\u3059\u308b\u306b\u306f\u3001 ==
\u3068 !=
\u306e\u4f7f\u7528\u65b9\u6cd5\u3092\u7406\u89e3\u3059\u308b\u3053\u3068\u304c\u4e0d\u53ef\u6b20\u3067\u3059\u3002\u3053\u308c\u3089\u306e\u6f14\u7b97\u5b50\u306f\u3001\u6bd4\u8f03\u53ef\u80fd\u306a\u88ab\u6f14\u7b97\u5b50\u3067\u4f7f\u7528\u3067\u304d\u307e\u3059\u3002
?
\u3001 >=
\u3001 <
\u3001\u304a\u3088\u3073 >
\u6f14\u7b97\u5b50\u3092\u6570\u5024\u578b\u3067\u4f7f\u7528\u3057\u3066\u5024\u3092\u6bd4\u8f03\u3057\u305f\u308a\u3001\u6587\u5b57\u5217\u3067\u5b57\u53e5\u9806\u5e8f\u3092\u6bd4\u8f03\u3057\u305f\u308a\u3059\u308b\u3053\u3068\u3082\u3067\u304d\u307e\u3059\u3002
\u88ab\u6f14\u7b97\u5b50\u304c\u6bd4\u8f03\u3067\u304d\u306a\u3044\u5834\u5408\uff08\u30b9\u30e9\u30a4\u30b9\u3068\u30de\u30c3\u30d7\u306a\u3069\uff09\u3001\u30ea\u30d5\u30ec\u30af\u30b7\u30e7\u30f3\u306a\u3069\u306e\u4ed6\u306e\u65b9\u6cd5\u3092\u5229\u7528\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u30ea\u30d5\u30ec\u30af\u30b7\u30e7\u30f3\u306f\u30e1\u30bf\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u306e\u4e00\u7a2e\u3067\u3042\u308a\u3001\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u304c\u305d\u306e\u69cb\u9020\u3068\u52d5\u4f5c\u3092\u5185\u7701\u3057\u3066\u5909\u66f4\u3059\u308b\u6a5f\u80fd\u3092\u6307\u3057\u307e\u3059\u3002\u305f\u3068\u3048\u3070\u3001Go\u8a00\u8a9e\u3067\u306f reflect.DeepEqual
\u3092\u4f7f\u7528\u3067\u304d\u307e\u3059\u3002\u3053\u306e\u95a2\u6570\u306f\u30012\u3064\u306e\u5024\u3092\u518d\u5e30\u7684\u306b\u8abf\u3079\u308b\u3053\u3068\u306b\u3088\u3063\u3066\u30012\u3064\u306e\u8981\u7d20\u304c\u5b8c\u5168\u306b\u7b49\u3057\u3044\u304b\u3069\u3046\u304b\u3092\u5831\u544a\u3057\u307e\u3059\u3002\u53d7\u3051\u5165\u308c\u3089\u308c\u308b\u8981\u7d20\u306f\u3001\u57fa\u672c\u578b\u306b\u52a0\u3048\u3066\u3001\u914d\u5217\u3001\u69cb\u9020\u4f53\u3001\u30b9\u30e9\u30a4\u30b9\u3001\u30de\u30c3\u30d7\u3001\u30dd\u30a4\u30f3\u30bf\u3001\u30a4\u30f3\u30bf\u30d5\u30a7\u30fc\u30b9\u3001\u95a2\u6570\u3067\u3059\u3002\u3057\u304b\u3057\u3001\u6700\u5927\u306e\u843d\u3068\u3057\u7a74\u306f\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u4e0a\u306e\u30da\u30ca\u30eb\u30c6\u30a3\u3067\u3059\u3002
\u5b9f\u884c\u6642\u306e\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u304c\u91cd\u8981\u306a\u5834\u5408\u306f\u3001\u72ec\u81ea\u306e\u30e1\u30bd\u30c3\u30c9\u3092\u5b9f\u88c5\u3059\u308b\u3053\u3068\u304c\u6700\u5584\u3068\u306a\u308b\u53ef\u80fd\u6027\u304c\u3042\u308a\u307e\u3059\u3002
\u8ffd\u8a18\uff1a\u6a19\u6e96\u30e9\u30a4\u30d6\u30e9\u30ea\u306b\u306f\u65e2\u306b\u6bd4\u8f03\u30e1\u30bd\u30c3\u30c9\u304c\u3044\u304f\u3064\u304b\u3042\u308b\u3053\u3068\u3092\u899a\u3048\u3066\u304a\u304f\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u305f\u3068\u3048\u3070\u3001\u6700\u9069\u5316\u3055\u308c\u305f bytes.Compare
\u95a2\u6570\u3092\u4f7f\u7528\u3057\u3066\u30012\u3064\u306e\u30d0\u30a4\u30c8\u30b9\u30e9\u30a4\u30b9\u3092\u6bd4\u8f03\u3067\u304d\u307e\u3059\u3002\u72ec\u81ea\u306e\u30e1\u30bd\u30c3\u30c9\u3092\u5b9f\u88c5\u3059\u308b\u524d\u306b\u3001\u8eca\u8f2a\u306e\u518d\u767a\u660e\u3092\u3057\u306a\u3044\u3088\u3046\u306b\u3057\u307e\u3057\u3087\u3046\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#_5","title":"\u5236\u5fa1\u69cb\u9020","text":""},{"location":"ja/#range-30","title":"\u8981\u7d20\u304crange
\u30eb\u30fc\u30d7\u5185\u3067\u30b3\u30d4\u30fc\u3055\u308c\u308b\u3053\u3068\u3092\u77e5\u3089\u306a\u3044 (#30)","text":"\u8981\u7d04 range
\u30eb\u30fc\u30d7\u5185\u306e value \u8981\u7d20\u306f\u30b3\u30d4\u30fc\u3067\u3059\u3002\u3057\u305f\u304c\u3063\u3066\u3001\u305f\u3068\u3048\u3070\u69cb\u9020\u4f53\u3092\u5909\u66f4\u3059\u308b\u306b\u306f\u3001\u305d\u306e\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u3092\u4ecb\u3057\u3066\u30a2\u30af\u30bb\u30b9\u3059\u308b\u304b\u3001\u5f93\u6765\u306e for
\u30eb\u30fc\u30d7\u3092\u4ecb\u3057\u3066\u30a2\u30af\u30bb\u30b9\u3057\u307e\u3057\u3087\u3046\uff08\u5909\u66f4\u3059\u308b\u8981\u7d20\u307e\u305f\u306f\u30d5\u30a3\u30fc\u30eb\u30c9\u304c\u30dd\u30a4\u30f3\u30bf\u3067\u3042\u308b\u5834\u5408\u3092\u9664\u304f\uff09\u3002
range \u30eb\u30fc\u30d7\u3092\u4f7f\u7528\u3059\u308b\u3068\u3001\u3055\u307e\u3056\u307e\u306a\u30c7\u30fc\u30bf\u69cb\u9020\u306b\u53cd\u5fa9\u51e6\u7406\u3092\u884c\u3046\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002
\u53e4\u5178\u7684\u306a for
\u30eb\u30fc\u30d7\u3068\u6bd4\u8f03\u3059\u308b\u3068\u3001range
\u30eb\u30fc\u30d7\u306f\u305d\u306e\u7c21\u6f54\u306a\u69cb\u6587\u306e\u304a\u304b\u3052\u3067\u3001\u3053\u308c\u3089\u306e\u30c7\u30fc\u30bf\u69cb\u9020\u306e\u3059\u3079\u3066\u306e\u8981\u7d20\u306b\u53cd\u5fa9\u51e6\u7406\u3092\u3059\u308b\u306e\u306b\u4fbf\u5229\u3067\u3059\u3002
\u305f\u3060\u3057\u3001range \u30eb\u30fc\u30d7\u5185\u306e\u5024\u8981\u7d20\u306f\u30b3\u30d4\u30fc\u3067\u3042\u308b\u3053\u3068\u3092\u899a\u3048\u3066\u304a\u304f\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u3057\u305f\u304c\u3063\u3066\u3001\u5024\u3092\u5909\u66f4\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u69cb\u9020\u4f53\u306e\u5834\u5408\u3001\u5909\u66f4\u3059\u308b\u5024\u307e\u305f\u306f\u30d5\u30a3\u30fc\u30eb\u30c9\u304c\u30dd\u30a4\u30f3\u30bf\u3067\u306a\u3044\u9650\u308a\u3001\u8981\u7d20\u81ea\u4f53\u3067\u306f\u306a\u304f\u30b3\u30d4\u30fc\u306e\u307f\u3092\u66f4\u65b0\u3057\u307e\u3059\u3002range \u30eb\u30fc\u30d7\u307e\u305f\u306f\u5f93\u6765\u306e for \u30eb\u30fc\u30d7\u3092\u4f7f\u7528\u3057\u3066\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u7d4c\u7531\u3067\u8981\u7d20\u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b\u3053\u3068\u304c\u63a8\u5968\u3055\u308c\u307e\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#range-31","title":"range
\u30eb\u30fc\u30d7\uff08\u30c1\u30e3\u30cd\u30eb\u3068\u914d\u5217\uff09\u3067\u306e\u5f15\u6570\u306e\u8a55\u4fa1\u65b9\u6cd5\u3092\u77e5\u3089\u306a\u3044 (#31)","text":"\u8981\u7d04 range
\u6f14\u7b97\u5b50\u306b\u6e21\u3055\u308c\u308b\u5f0f\u306f\u30eb\u30fc\u30d7\u306e\u958b\u59cb\u524d\u306b 1 \u56de\u3060\u3051\u8a55\u4fa1\u3055\u308c\u308b\u3053\u3068\u3092\u7406\u89e3\u3059\u308b\u3068\u3001\u30c1\u30e3\u30cd\u30eb\u307e\u305f\u306f\u30b9\u30e9\u30a4\u30b9\u306e\u53cd\u5fa9\u51e6\u7406\u306b\u304a\u3051\u308b\u975e\u52b9\u7387\u306a\u5272\u308a\u5f53\u3066\u306a\u3069\u306e\u3042\u308a\u304c\u3061\u306a\u9593\u9055\u3044\u3092\u56de\u907f\u3067\u304d\u307e\u3059\u3002
range \u30eb\u30fc\u30d7\u306f\u3001\uff08\u30bf\u30a4\u30d7\u306b\u95a2\u4fc2\u306a\u304f\uff09\u30b3\u30d4\u30fc\u3092\u5b9f\u884c\u3059\u308b\u3053\u3068\u306b\u3088\u308a\u3001\u30eb\u30fc\u30d7\u306e\u958b\u59cb\u524d\u306b\u3001\u6307\u5b9a\u3055\u308c\u305f\u5f0f\u3092 1 \u56de\u3060\u3051\u8a55\u4fa1\u3057\u307e\u3059\u3002\u305f\u3068\u3048\u3070\u3001\u8aa4\u3063\u305f\u8981\u7d20\u306b\u30a2\u30af\u30bb\u30b9\u3057\u3066\u3057\u307e\u3046\u3001\u3068\u3044\u3046\u3088\u3046\u306a\u3042\u308a\u304c\u3061\u306a\u9593\u9055\u3044\u3092\u907f\u3051\u308b\u305f\u3081\u306b\u3001\u3053\u306e\u52d5\u4f5c\u3092\u899a\u3048\u3066\u304a\u304f\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u305f\u3068\u3048\u3070
a := [3]int{0, 1, 2}\nfor i, v := range a {\n a[2] = 10\n if i == 2 {\n fmt.Println(v)\n }\n}\n
\u3053\u306e\u30b3\u30fc\u30c9\u306f\u3001\u6700\u5f8c\u306e\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u3092 10 \u306b\u66f4\u65b0\u3057\u307e\u3059\u3002\u3057\u304b\u3057\u3001\u3053\u306e\u30b3\u30fc\u30c9\u3092\u5b9f\u884c\u3059\u308b\u3068\u300110 \u306f\u51fa\u529b\u3055\u308c\u307e\u305b\u3093\u3002 2 \u304c\u51fa\u529b\u3055\u308c\u307e\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#range-32","title":"range
\u30eb\u30fc\u30d7\u5185\u306b\u304a\u3051\u308b\u30dd\u30a4\u30f3\u30bf\u8981\u7d20\u306e\u4f7f\u7528\u304c\u53ca\u307c\u3059\u5f71\u97ff\u3092\u5206\u304b\u3063\u3066\u3044\u306a\u3044 (#32)","text":"\u8981\u7d04 \u30ed\u30fc\u30ab\u30eb\u5909\u6570\u3092\u4f7f\u7528\u3059\u308b\u304b\u3001\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u3092\u4f7f\u7528\u3057\u3066\u8981\u7d20\u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b\u3068\u3001\u30eb\u30fc\u30d7\u5185\u3067\u30dd\u30a4\u30f3\u30bf\u3092\u30b3\u30d4\u30fc\u3059\u308b\u969b\u306e\u9593\u9055\u3044\u3092\u9632\u3050\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002
range
\u30eb\u30fc\u30d7\u3092\u4f7f\u7528\u3057\u3066\u30c7\u30fc\u30bf\u69cb\u9020\u306b\u53cd\u5fa9\u51e6\u7406\u3092\u65bd\u3059\u5834\u5408\u3001\u3059\u3079\u3066\u306e\u5024\u304c\u5358\u4e00\u306e\u4e00\u610f\u306e\u30a2\u30c9\u30ec\u30b9\u3092\u6301\u3064\u4e00\u610f\u306e\u5909\u6570\u306b\u5272\u308a\u5f53\u3066\u3089\u308c\u308b\u3053\u3068\u3092\u601d\u3044\u51fa\u3057\u3066\u304f\u3060\u3055\u3044\u3002\u3086\u3048\u306b\u3001\u5404\u53cd\u5fa9\u51e6\u7406\u4e2d\u306b\u3053\u306e\u5909\u6570\u3092\u53c2\u7167\u3059\u308b\u30dd\u30a4\u30f3\u30bf\u3092\u4fdd\u5b58\u3059\u308b\u3068\u3001\u540c\u3058\u8981\u7d20\u3001\u3064\u307e\u308a\u6700\u65b0\u306e\u8981\u7d20\u3092\u53c2\u7167\u3059\u308b\u540c\u3058\u30dd\u30a4\u30f3\u30bf\u3092\u4fdd\u5b58\u3059\u308b\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002\u3053\u306e\u554f\u984c\u306f\u3001\u30eb\u30fc\u30d7\u306e\u30b9\u30b3\u30fc\u30d7\u5185\u306b\u30ed\u30fc\u30ab\u30eb\u5909\u6570\u3092\u5f37\u5236\u7684\u306b\u4f5c\u6210\u3059\u308b\u304b\u3001\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u3092\u4ecb\u3057\u3066\u30b9\u30e9\u30a4\u30b9\u8981\u7d20\u3092\u53c2\u7167\u3059\u308b\u30dd\u30a4\u30f3\u30bf\u3092\u4f5c\u6210\u3059\u308b\u3053\u3068\u3067\u89e3\u6c7a\u3067\u304d\u307e\u3059\u3002\u3069\u3061\u3089\u306e\u89e3\u6c7a\u7b56\u3067\u3082\u554f\u984c\u3042\u308a\u307e\u305b\u3093\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#33","title":"\u30de\u30c3\u30d7\u306e\u53cd\u5fa9\u51e6\u7406\u4e2d\u306b\u8aa4\u3063\u305f\u4eee\u5b9a\u3092\u3059\u308b\uff08\u53cd\u5fa9\u51e6\u7406\u4e2d\u306e\u9806\u5e8f\u4ed8\u3051\u3068\u30de\u30c3\u30d7\u306e\u633f\u5165\uff09 (#33)","text":"\u8981\u7d04\u30de\u30c3\u30d7\u3092\u4f7f\u7528\u3059\u308b\u3068\u304d\u306b\u4e88\u6e2c\u53ef\u80fd\u306a\u51fa\u529b\u3092\u4fdd\u8a3c\u3059\u308b\u306b\u306f\u3001\u30de\u30c3\u30d7\u306e\u30c7\u30fc\u30bf\u69cb\u9020\u304c\u6b21\u306e\u3068\u304a\u308a\u3067\u3042\u308b\u3053\u3068\u306b\u6ce8\u610f\u3057\u3066\u304f\u3060\u3055\u3044\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#break-34","title":"break
\u6587\u304c\u3069\u306e\u3088\u3046\u306b\u6a5f\u80fd\u3059\u308b\u304b\u3092\u5206\u304b\u3063\u3066\u3044\u306a\u3044 (#34)","text":"\u8981\u7d04 \u30e9\u30d9\u30eb\u3068 break
\u307e\u305f\u306f continue
\u306e\u4f75\u7528\u306f\u3001\u7279\u5b9a\u306e\u547d\u4ee4\u6587\u3092\u5f37\u5236\u7684\u306b\u4e2d\u65ad\u3057\u307e\u3059\u3002\u3053\u308c\u306f\u3001\u30eb\u30fc\u30d7\u5185\u306e switch
\u307e\u305f\u306f select
\u6587\u3067\u5f79\u7acb\u3061\u307e\u3059\u3002
\u901a\u5e38\u3001break \u6587\u306f\u30eb\u30fc\u30d7\u306e\u5b9f\u884c\u3092\u7d42\u4e86\u3059\u308b\u305f\u3081\u306b\u4f7f\u7528\u3055\u308c\u307e\u3059\u3002\u30eb\u30fc\u30d7\u304c switch \u307e\u305f\u306f select \u3068\u7d44\u307f\u5408\u308f\u305b\u3066\u4f7f\u7528\u200b\u200b\u3055\u308c\u308b\u5834\u5408\u3001\u76ee\u7684\u306e\u547d\u4ee4\u6587\u3067\u306f\u306a\u3044\u306e\u306b\u4e2d\u65ad\u3055\u305b\u3066\u3057\u307e\u3046\u3001\u3068\u3044\u3046\u30df\u30b9\u3092\u3059\u308b\u3053\u3068\u304c\u958b\u767a\u8005\u306b\u306f\u3088\u304f\u3042\u308a\u307e\u3059\u3002\u305f\u3068\u3048\u3070
for i := 0; i < 5; i++ {\n fmt.Printf(\"%d \", i)\n\n switch i {\n default:\n case 2:\n break\n }\n}\n
break \u6587\u306f for
\u30eb\u30fc\u30d7\u3092\u7d42\u4e86\u3055\u305b\u308b\u306e\u3067\u306f\u306a\u304f\u3001\u4ee3\u308f\u308a\u306b switch
\u6587\u3092\u7d42\u4e86\u3055\u305b\u307e\u3059\u3002\u3057\u305f\u304c\u3063\u3066\u3001\u3053\u306e\u30b3\u30fc\u30c9\u306f 0 \u304b\u3089 2 \u307e\u3067\u3092\u53cd\u5fa9\u3059\u308b\u4ee3\u308f\u308a\u306b\u30010 \u304b\u3089 4 \u307e\u3067\u3092\u53cd\u5fa9\u3057\u307e\u3059\uff080 1 2 3 4
\uff09\u3002
\u899a\u3048\u3066\u304a\u304f\u3079\u304d\u91cd\u8981\u306a\u30eb\u30fc\u30eb\u306e1\u3064\u306f\u3001 break
\u6587\u306f\u6700\u3082\u5185\u5074\u306e for
\u3001switch
\u3001\u307e\u305f\u306f select
\u6587\u306e\u5b9f\u884c\u3092\u7d42\u4e86\u3059\u308b\u3068\u3044\u3046\u3053\u3068\u3067\u3059\u3002\u524d\u306e\u4f8b\u3067\u306f\u3001switch
\u6587\u3092\u7d42\u4e86\u3057\u307e\u3059\u3002
switch
\u6587\u306e\u4ee3\u308f\u308a\u306b\u30eb\u30fc\u30d7\u3092\u4e2d\u65ad\u3059\u308b\u6700\u3082\u6163\u7528\u7684\u306a\u65b9\u6cd5\u306f\u30e9\u30d9\u30eb\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u3067\u3059\u3002
loop:\n for i := 0; i < 5; i++ {\n fmt.Printf(\"%d \", i)\n\n switch i {\n default:\n case 2:\n break loop\n }\n }\n
\u3053\u3053\u3067\u306f\u3001loop
\u30e9\u30d9\u30eb\u3092 for
\u30eb\u30fc\u30d7\u306b\u95a2\u9023\u4ed8\u3051\u307e\u3059\u3002 \u6b21\u306b\u3001break
\u6587\u306b loop
\u30e9\u30d9\u30eb\u3092\u6307\u5b9a\u3059\u308b\u306e\u3067\u3001switch \u3067\u306f\u306a\u304f loop \u304c\u4e2d\u65ad\u3055\u308c\u307e\u3059\u3002\u3088\u3063\u3066\u3001\u3053\u306e\u65b0\u3057\u3044\u30d0\u30fc\u30b8\u30e7\u30f3\u306f\u4e88\u60f3\u3069\u304a\u308a 0 1 2
\u3092\u51fa\u529b\u3057\u307e\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#defer-35","title":"\u30eb\u30fc\u30d7\u5185\u3067defer
\u3092\u4f7f\u7528\u3059\u308b (#35)","text":"\u8981\u7d04 \u95a2\u6570\u5185\u306e\u30eb\u30fc\u30d7\u30ed\u30b8\u30c3\u30af\u306e\u62bd\u51fa\u306f\u3001\u5404\u53cd\u5fa9\u306e\u6700\u5f8c\u3067\u306e defer
\u6587\u306e\u5b9f\u884c\u306b\u3064\u306a\u304c\u308a\u307e\u3059\u3002
defer
\u6587\u306f\u3001\u4e0a\u4f4d\u30d6\u30ed\u30c3\u30af\u306e\u95a2\u6570\u304c\u623b\u308b\u307e\u3067\u547c\u3073\u51fa\u3057\u306e\u5b9f\u884c\u3092\u9045\u3089\u305b\u307e\u3059\u3002\u3053\u308c\u306f\u4e3b\u306b\u5b9a\u578b\u30b3\u30fc\u30c9\u3092\u524a\u6e1b\u3059\u308b\u305f\u3081\u306b\u4f7f\u7528\u3055\u308c\u307e\u3059\u3002\u305f\u3068\u3048\u3070\u3001\u30ea\u30bd\u30fc\u30b9\u3092\u6700\u7d42\u7684\u306b\u9589\u3058\u308b\u5fc5\u8981\u304c\u3042\u308b\u5834\u5408\u306f\u3001defer
\u3092\u4f7f\u7528\u3057\u3066\u3001return
\u3092\u5b9f\u884c\u3059\u308b\u524d\u306b\u30af\u30ed\u30fc\u30b8\u30e3\u547c\u3073\u51fa\u3057\u3092\u7e70\u308a\u8fd4\u3059\u3053\u3068\u3092\u907f\u3051\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002
defer
\u3067\u3088\u304f\u3042\u308b\u30df\u30b9\u306e1\u3064\u306f\u3001\u4e0a\u4f4d\u30d6\u30ed\u30c3\u30af \u306e\u95a2\u6570\u304c\u623b\u3063\u305f\u3068\u304d\u306b\u95a2\u6570\u547c\u3073\u51fa\u3057\u304c\u30b9\u30b1\u30b8\u30e5\u30fc\u30eb\u3055\u308c\u308b\u3053\u3068\u3092\u5fd8\u308c\u308b\u3053\u3068\u3067\u3059\u3002\u305f\u3068\u3048\u3070
func readFiles(ch <-chan string) error {\n for path := range ch {\n file, err := os.Open(path)\n if err != nil {\n return err\n }\n\n defer file.Close()\n\n // \u30d5\u30a1\u30a4\u30eb\u306e\u51e6\u7406\u3092\u3059\u308b\n }\n return nil\n}\n
defer
\u547c\u3073\u51fa\u3057\u306f\u3001\u5404\u30eb\u30fc\u30d7\u53cd\u5fa9\u4e2d\u3067\u306f\u306a\u304f\u3001readFiles
\u95a2\u6570\u304c\u8fd4\u3055\u308c\u305f\u3068\u304d\u306b\u5b9f\u884c\u3055\u308c\u307e\u3059\u3002 readFiles
\u304c\u8fd4\u3089\u306a\u3044\u5834\u5408\u3001\u30d5\u30a1\u30a4\u30eb\u8a18\u8ff0\u5b50\u306f\u6c38\u4e45\u306b\u958b\u3044\u305f\u307e\u307e\u306b\u306a\u308a\u3001\u30ea\u30fc\u30af\u304c\u767a\u751f\u3057\u307e\u3059\u3002
\u3053\u306e\u554f\u984c\u3092\u89e3\u6c7a\u3059\u308b\u305f\u3081\u306e\u4e00\u822c\u7684\u306a\u624b\u6bb5\u306e1\u3064\u306f\u3001 defer
\u306e\u5f8c\u306b\u3001\u5404\u53cd\u5fa9\u4e2d\u306b\u547c\u3073\u51fa\u3055\u308c\u308b\u4e0a\u4f4d\u30d6\u30ed\u30c3\u30af\u306e\u95a2\u6570\u3092\u4f5c\u6210\u3059\u308b\u3053\u3068\u3067\u3059\u3002
func readFiles(ch <-chan string) error {\n for path := range ch {\n if err := readFile(path); err != nil {\n return err\n }\n }\n return nil\n}\n\nfunc readFile(path string) error {\n file, err := os.Open(path)\n if err != nil {\n return err\n }\n\n defer file.Close()\n\n // \u30d5\u30a1\u30a4\u30eb\u306e\u51e6\u7406\u3092\u3059\u308b\n return nil\n}\n
\u5225\u306e\u89e3\u6c7a\u7b56\u306f\u3001readFile
\u95a2\u6570\u3092\u30af\u30ed\u30fc\u30b8\u30e3\u306b\u3059\u308b\u3053\u3068\u3067\u3059\u304c\u3001\u672c\u8cea\u7684\u306b\u306f\u540c\u3058\u3067\u3059\u3002\u5225\u306e\u4e0a\u4f4d\u30d6\u30ed\u30c3\u30af\u306e\u95a2\u6570\u3092\u8ffd\u52a0\u3057\u3066\u3001\u5404\u53cd\u5fa9\u4e2d\u306b defer
\u547c\u3073\u51fa\u3057\u3092\u5b9f\u884c\u3057\u307e\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#_6","title":"\u6587\u5b57\u5217","text":""},{"location":"ja/#36","title":"\u30eb\u30fc\u30f3\u3092\u7406\u89e3\u3057\u3066\u3044\u306a\u3044 (#36)","text":"\u8981\u7d04\u30eb\u30fc\u30f3\u304c Unicode \u30b3\u30fc\u30c9\u30dd\u30a4\u30f3\u30c8\u306e\u6982\u5ff5\u306b\u5bfe\u5fdc\u3057\u3001\u8907\u6570\u306e\u30d0\u30a4\u30c8\u3067\u69cb\u6210\u3055\u308c\u308b\u53ef\u80fd\u6027\u304c\u3042\u308b\u3053\u3068\u3092\u7406\u89e3\u3059\u308b\u3053\u3068\u306f\u3001 Go \u958b\u767a\u8005\u304c\u6587\u5b57\u5217\u3092\u6b63\u78ba\u306b\u64cd\u4f5c\u3059\u308b\u305f\u3081\u306b\u4e0d\u53ef\u6b20\u3067\u3059\u3002
Go\u8a00\u8a9e\u3067\u306f\u30eb\u30fc\u30f3\u304c\u3042\u3089\u3086\u308b\u5834\u6240\u306b\u4f7f\u7528\u3055\u308c\u308b\u305f\u3081\u3001\u6b21\u306e\u70b9\u3092\u7406\u89e3\u3059\u308b\u3053\u3068\u304c\u91cd\u8981\u3067\u3059\u3002
rune
\u306f Unicode \u30b3\u30fc\u30c9\u30dd\u30a4\u30f3\u30c8\u306e\u6982\u5ff5\u306b\u5bfe\u5fdc\u3057\u3001\u5358\u4e00\u306e\u5024\u3067\u8868\u3055\u308c\u308b\u30a2\u30a4\u30c6\u30e0\u3092\u610f\u5473\u3057\u307e\u3059\u3002len()
\u3092\u4f7f\u7528\u3059\u308b\u3068\u3001\u30eb\u30fc\u30f3\u6570\u3067\u306f\u306a\u304f\u30d0\u30a4\u30c8\u6570\u304c\u8fd4\u3055\u308c\u307e\u3059\u3002\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#37","title":"\u6587\u5b57\u5217\u306b\u5bfe\u3059\u308b\u4e0d\u6b63\u306a\u53cd\u5fa9\u51e6\u7406 (#37)","text":"\u8981\u7d04range
\u6f14\u7b97\u5b50\u3092\u4f7f\u7528\u3057\u3066\u6587\u5b57\u5217\u3092\u53cd\u5fa9\u51e6\u7406\u3059\u308b\u3068\u3001\u30eb\u30fc\u30f3\u306e\u30d0\u30a4\u30c8\u30b7\u30fc\u30b1\u30f3\u30b9\u306e\u958b\u59cb\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u306b\u5bfe\u5fdc\u3059\u308b\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u3092\u4f7f\u7528\u3057\u3066\u30eb\u30fc\u30f3\u304c\u53cd\u5fa9\u51e6\u7406\u3055\u308c\u307e\u3059\u3002\u7279\u5b9a\u306e\u30eb\u30fc\u30f3\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\uff08 3 \u756a\u76ee\u306e\u30eb\u30fc\u30f3\u306a\u3069\uff09\u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b\u306b\u306f\u3001\u6587\u5b57\u5217\u3092 []rune
\u306b\u5909\u63db\u3057\u307e\u3059\u3002
\u6587\u5b57\u5217\u306e\u53cd\u5fa9\u51e6\u7406\u306f\u3001\u958b\u767a\u8005\u306b\u3068\u3063\u3066\u4e00\u822c\u7684\u306a\u64cd\u4f5c\u3067\u3059\u3002\u304a\u305d\u3089\u304f\u3001\u6587\u5b57\u5217\u5185\u306e\u5404\u30eb\u30fc\u30f3\u306b\u5bfe\u3057\u3066\u64cd\u4f5c\u3092\u5b9f\u884c\u3059\u308b\u304b\u3001\u7279\u5b9a\u306e\u90e8\u5206\u6587\u5b57\u5217\u3092\u691c\u7d22\u3059\u308b\u72ec\u81ea\u306e\u95a2\u6570\u3092\u5b9f\u88c5\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u3067\u3057\u3087\u3046\u3002\u3069\u3061\u3089\u306e\u5834\u5408\u3082\u3001\u6587\u5b57\u5217\u306e\u7570\u306a\u308b\u30eb\u30fc\u30f3\u3092\u53cd\u5fa9\u51e6\u7406\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u3057\u304b\u3057\u3001\u53cd\u5fa9\u51e6\u7406\u304c\u3069\u306e\u3088\u3046\u306b\u6a5f\u80fd\u3059\u308b\u304b\u306b\u3064\u3044\u3066\u306f\u56f0\u60d1\u3057\u3084\u3059\u3044\u3067\u3059\u3002
\u6b21\u306e\u4f8b\u3092\u8003\u3048\u3066\u307f\u307e\u3057\u3087\u3046\u3002
s := \"h\u00eallo\"\nfor i := range s {\n fmt.Printf(\"position %d: %c\\n\", i, s[i])\n}\nfmt.Printf(\"len=%d\\n\", len(s))\n
position 0: h\nposition 1: \u00c3\nposition 3: l\nposition 4: l\nposition 5: o\nlen=6\n
\u6df7\u4e71\u3092\u62db\u304f\u53ef\u80fd\u6027\u306e\u3042\u308b 3 \u70b9\u3092\u53d6\u308a\u4e0a\u3052\u307e\u3057\u3087\u3046\u3002
\u7d50\u679c\u306e\u6700\u5f8c\u304b\u3089\u898b\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u3002len \u306f\u30eb\u30fc\u30f3\u6570\u3067\u306f\u306a\u304f\u3001\u6587\u5b57\u5217\u5185\u306e\u30d0\u30a4\u30c8\u6570\u3092\u8fd4\u3059\u3053\u3068\u306f\u3059\u3067\u306b\u8ff0\u3079\u307e\u3057\u305f\u3002\u6587\u5b57\u5217\u30ea\u30c6\u30e9\u30eb\u3092 s
\u306b\u5272\u308a\u5f53\u3066\u3066\u3044\u308b\u305f\u3081\u3001s
\u306f UTF-8 \u6587\u5b57\u5217\u3067\u3059\u3002\u4e00\u65b9\u3001\u7279\u6b8a\u6587\u5b57\u300c\u00ea\u300d\u306f 1 \u30d0\u30a4\u30c8\u3067\u30a8\u30f3\u30b3\u30fc\u30c9\u3055\u308c\u307e\u305b\u3093\u3002 2 \u30d0\u30a4\u30c8\u5fc5\u8981\u3067\u3059\u3002\u3057\u305f\u304c\u3063\u3066\u3001len(s)
\u3092\u547c\u3073\u51fa\u3059\u3068 6 \u304c\u8fd4\u3055\u308c\u307e\u3059\u3002
\u524d\u306e\u4f8b\u3067\u306f\u3001\u5404\u30eb\u30fc\u30f3\u3092\u53cd\u5fa9\u51e6\u7406\u3057\u3066\u3044\u306a\u3044\u3053\u3068\u3092\u7406\u89e3\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u4ee3\u308f\u308a\u306b\u3001\u30eb\u30fc\u30f3\u306e\u5404\u958b\u59cb\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u3092\u53cd\u5fa9\u51e6\u7406\u3057\u307e\u3059\u3002
s[i]
\u3092\u51fa\u529b\u3057\u3066\u3082 i \u756a\u76ee\u306e\u30eb\u30fc\u30f3\u306f\u51fa\u529b\u3055\u308c\u307e\u305b\u3093\u3002\u30a4\u30f3\u30c7\u30c3\u30af\u30b9 i
\u306e\u30d0\u30a4\u30c8\u306e UTF-8 \u8868\u73fe\u3092\u51fa\u529b\u3057\u307e\u3059\u3002\u3057\u305f\u304c\u3063\u3066\u3001 h\u00eallo
\u306e\u4ee3\u308f\u308a\u306b h\u00c3llo
\u3092\u51fa\u529b\u304c\u3055\u308c\u307e\u3059\u3002
\u3055\u307e\u3056\u307e\u306a\u30eb\u30fc\u30f3\u6587\u5b57\u3092\u3059\u3079\u3066\u51fa\u529b\u3057\u305f\u3044\u5834\u5408\u306f\u3001 range
\u6f14\u7b97\u5b50\u306e value \u8981\u7d20\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002
s := \"h\u00eallo\"\nfor i, r := range s {\n fmt.Printf(\"position %d: %c\\n\", i, r)\n}\n
\u307e\u305f\u306f\u3001\u6587\u5b57\u5217\u3092\u30eb\u30fc\u30f3\u306e\u30b9\u30e9\u30a4\u30b9\u306b\u5909\u63db\u3057\u3001\u305d\u308c\u3092\u53cd\u5fa9\u51e6\u7406\u3059\u308b\u3053\u3068\u3082\u3067\u304d\u307e\u3059\u3002
s := \"h\u00eallo\"\nrunes := []rune(s)\nfor i, r := range runes {\n fmt.Printf(\"position %d: %c\\n\", i, r)\n}\n
\u3053\u306e\u89e3\u6c7a\u7b56\u3067\u306f\u3001\u4ee5\u524d\u306e\u89e3\u6c7a\u7b56\u3068\u6bd4\u8f03\u3057\u3066\u5b9f\u884c\u6642\u306e\u30aa\u30fc\u30d0\u30fc\u30d8\u30c3\u30c9\u304c\u767a\u751f\u3059\u308b\u3053\u3068\u306b\u6ce8\u610f\u3057\u3066\u304f\u3060\u3055\u3044\u3002\u5b9f\u969b\u3001\u6587\u5b57\u5217\u3092\u30eb\u30fc\u30f3\u306e\u30b9\u30e9\u30a4\u30b9\u306b\u5909\u63db\u3059\u308b\u306b\u306f\u3001\u8ffd\u52a0\u306e\u30b9\u30e9\u30a4\u30b9\u3092\u5272\u308a\u5f53\u3066\u3001\u30d0\u30a4\u30c8\u3092\u30eb\u30fc\u30f3\u306b\u5909\u63db\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u6587\u5b57\u5217\u306e\u30d0\u30a4\u30c8\u6570\u3092 n \u3068\u3059\u308b\u3068\u3001\u6642\u9593\u8a08\u7b97\u91cf\u306f O(n) \u306b\u306a\u308a\u307e\u3059\u3002\u3057\u305f\u304c\u3063\u3066\u3001\u3059\u3079\u3066\u306e\u30eb\u30fc\u30f3\u3092\u53cd\u5fa9\u51e6\u7406\u3059\u308b\u5834\u5408\u306f\u3001\u6700\u521d\u306e\u89e3\u6c7a\u7b56\u3092\u4f7f\u7528\u3059\u308b\u3079\u304d\u3067\u3059\u3002
\u305f\u3060\u3057\u3001\u6700\u521d\u306e\u65b9\u6cd5\u3092\u4f7f\u7528\u3057\u3066\u6587\u5b57\u5217\u306e i \u756a\u76ee\u306e\u30eb\u30fc\u30f3\u306b\u30a2\u30af\u30bb\u30b9\u3057\u305f\u3044\u5834\u5408\u306f\u3001\u30eb\u30fc\u30f3\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u306b\u30a2\u30af\u30bb\u30b9\u3067\u304d\u307e\u305b\u3093\u3002\u4ee3\u308f\u308a\u306b\u3001\u30d0\u30a4\u30c8\u30b7\u30fc\u30b1\u30f3\u30b9\u5185\u306e\u30eb\u30fc\u30f3\u306e\u958b\u59cb\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u304c\u308f\u304b\u308a\u307e\u3059\u3002
s := \"h\u00eallo\"\nr := []rune(s)[4]\nfmt.Printf(\"%c\\n\", r) // o\n
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#trim-38","title":"trim \u95a2\u6570\u306e\u8aa4\u7528 (#38)","text":"\u8981\u7d04strings.TrimRight
\u30fb strings.TrimLeft
\u306f\u3001\u6307\u5b9a\u3055\u308c\u305f\u30bb\u30c3\u30c8\u306b\u542b\u307e\u308c\u308b\u3059\u3079\u3066\u306e\u672b\u5c3e\u30fb\u5148\u982d\u306e\u30eb\u30fc\u30f3\u3092\u524a\u9664\u3057\u307e\u3059\u304c\u3001 strings.TrimSuffix
\u30fb strings.TrimPrefix
\u306f\u3001\u6307\u5b9a\u3055\u308c\u305f\u63a5\u5c3e\u8f9e\u30fb\u63a5\u982d\u8f9e\u306e\u306a\u3044\u6587\u5b57\u5217\u3092\u8fd4\u3057\u307e\u3059\u3002
\u305f\u3068\u3048\u3070
fmt.Println(strings.TrimRight(\"123oxo\", \"xo\"))\n
\u306f 123 \u3092\u51fa\u529b\u3057\u307e\u3059
\u9006\u306b\u3001 strings.TrimLeft
\u306f\u3001\u30bb\u30c3\u30c8\u306b\u542b\u307e\u308c\u308b\u5148\u982d\u306e\u30eb\u30fc\u30f3\u3092\u3059\u3079\u3066\u524a\u9664\u3057\u307e\u3059\u3002
\u4e00\u65b9\u3001strings.TrimSuffix
\u30fb strings.TrimPrefix
\u306f\u3001\u6307\u5b9a\u3055\u308c\u305f\u672b\u5c3e\u306e\u63a5\u5c3e\u8f9e\u30fb\u63a5\u982d\u8f9e\u3092\u9664\u3044\u305f\u6587\u5b57\u5217\u3092\u8fd4\u3057\u307e\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#39","title":"\u6700\u9069\u5316\u304c\u4e0d\u5341\u5206\u306a\u6587\u5b57\u5217\u306e\u9023\u7d50 (#39)","text":"\u8981\u7d04\u6587\u5b57\u5217\u306e\u30ea\u30b9\u30c8\u306e\u9023\u7d50\u306f\u3001\u53cd\u5fa9\u3054\u3068\u306b\u65b0\u3057\u3044\u6587\u5b57\u5217\u304c\u5272\u308a\u5f53\u3066\u3089\u308c\u306a\u3044\u3088\u3046\u306b\u3001strings.Builder
\u3092\u4f7f\u7528\u3057\u3066\u884c\u3046\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002
+=
\u6f14\u7b97\u5b50\u3092\u7528\u3044\u3066\u30b9\u30e9\u30a4\u30b9\u306e\u3059\u3079\u3066\u306e\u6587\u5b57\u5217\u8981\u7d20\u3092\u9023\u7d50\u3059\u308b concat
\u95a2\u6570\u3092\u8003\u3048\u3066\u307f\u307e\u3057\u3087\u3046\u3002
func concat(values []string) string {\n s := \"\"\n for _, value := range values {\n s += value\n }\n return s\n}\n
\u5404\u53cd\u5fa9\u4e2d\u306b\u3001 +=
\u6f14\u7b97\u5b50\u306f s
\u3068 value \u6587\u5b57\u5217\u3092\u9023\u7d50\u3057\u307e\u3059\u3002\u4e00\u898b\u3059\u308b\u3068\u3001\u3053\u306e\u95a2\u6570\u306f\u9593\u9055\u3063\u3066\u3044\u306a\u3044\u3088\u3046\u306b\u898b\u3048\u308b\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002\u3057\u304b\u3057\u3001\u3053\u306e\u5b9f\u88c5\u306f\u3001\u6587\u5b57\u5217\u306e\u6838\u3068\u306a\u308b\u7279\u6027\u306e1\u3064\u3067\u3042\u308b\u4e0d\u5909\u6027\u3092\u5fd8\u308c\u3066\u3044\u307e\u3059\u3002\u3057\u305f\u304c\u3063\u3066\u3001\u5404\u53cd\u5fa9\u3067\u306f s
\u306f\u66f4\u65b0\u3055\u308c\u307e\u305b\u3093\u3002\u30e1\u30e2\u30ea\u5185\u306b\u65b0\u3057\u3044\u6587\u5b57\u5217\u3092\u518d\u5272\u308a\u5f53\u3066\u3059\u308b\u305f\u3081\u3001\u3053\u306e\u95a2\u6570\u306e\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u306b\u5927\u304d\u306a\u5f71\u97ff\u3092\u4e0e\u3048\u307e\u3059\u3002
\u5e78\u3044\u306a\u3053\u3068\u306b\u3001 strings.Builder
\u3092\u7528\u3044\u308b\u3053\u3068\u3067\u3001\u3053\u306e\u554f\u984c\u306b\u5bfe\u51e6\u3059\u308b\u89e3\u6c7a\u7b56\u304c\u3042\u308a\u307e\u3059\u3002
func concat(values []string) string {\n sb := strings.Builder{}\n for _, value := range values {\n _, _ = sb.WriteString(value)\n }\n return sb.String()\n}\n
\u5404\u53cd\u5fa9\u4e2d\u306b\u3001value \u306e\u5185\u5bb9\u3092\u5185\u90e8\u30d0\u30c3\u30d5\u30a1\u306b\u8ffd\u52a0\u3059\u308b WriteString
\u30e1\u30bd\u30c3\u30c9\u3092\u547c\u3073\u51fa\u3057\u3066\u7d50\u679c\u306e\u6587\u5b57\u5217\u3092\u69cb\u7bc9\u3057\u3001\u30e1\u30e2\u30ea\u306e\u30b3\u30d4\u30fc\u3092\u6700\u5c0f\u9650\u306b\u6291\u3048\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3057\u305f\u3002
WriteString
\u306f 2 \u756a\u76ee\u306e\u51fa\u529b\u3068\u3057\u3066\u30a8\u30e9\u30fc\u3092\u8fd4\u3057\u307e\u3059\u304c\u3001\u610f\u56f3\u7684\u306b\u7121\u8996\u3057\u307e\u3057\u3087\u3046\u3002\u5b9f\u969b\u3001\u3053\u306e\u30e1\u30bd\u30c3\u30c9\u306f nil \u30a8\u30e9\u30fc\u4ee5\u5916\u3092\u8fd4\u3059\u3053\u3068\u306f\u3042\u308a\u307e\u305b\u3093\u3002\u3067\u306f\u3001\u3053\u306e\u30e1\u30bd\u30c3\u30c9\u304c\u30b7\u30b0\u30cd\u30c1\u30e3\u306e\u4e00\u90e8\u3068\u3057\u3066\u30a8\u30e9\u30fc\u3092\u8fd4\u3059\u76ee\u7684\u306f\u4f55\u3067\u3057\u3087\u3046\u304b\u3002strings.Builder
\u306f io.StringWriter
\u30a4\u30f3\u30bf\u30d5\u30a7\u30fc\u30b9\u3092\u5b9f\u88c5\u3057\u3066\u304a\u308a\u3001\u3053\u308c\u306b\u306f WriteString(s string) (n int, err error)
\u3068\u3044\u30461\u3064\u306e\u30e1\u30bd\u30c3\u30c9\u304c\u542b\u307e\u308c\u3066\u3044\u307e\u3059\u3002\u3057\u305f\u304c\u3063\u3066\u3001\u3053\u306e\u30a4\u30f3\u30bf\u30d5\u30a7\u30fc\u30b9\u306b\u6e96\u62e0\u3059\u308b\u306b\u306f\u3001WriteString
\u306f\u30a8\u30e9\u30fc\u3092\u8fd4\u3055\u306a\u3051\u308c\u3070\u306a\u3089\u306a\u3044\u306e\u3067\u3059\u3002
\u5185\u90e8\u7684\u306b\u306f\u3001strings.Builder
\u306f\u30d0\u30a4\u30c8\u30b9\u30e9\u30a4\u30b9\u3092\u4fdd\u6301\u3057\u307e\u3059\u3002 WriteString
\u3092\u547c\u3073\u51fa\u3059\u305f\u3073\u306b\u3001\u3053\u306e\u30b9\u30e9\u30a4\u30b9\u306b\u8ffd\u52a0\u3059\u308b\u547c\u3073\u51fa\u3057\u304c\u884c\u308f\u308c\u307e\u3059\u3002\u3053\u308c\u306b\u306f2\u3064\u306e\u5f71\u97ff\u304c\u3042\u308a\u307e\u3059\u3002\u307e\u305a\u3001 append
\u306e\u547c\u3073\u51fa\u3057\u304c\u885d\u7a81\u72b6\u614b\u3092\u5f15\u304d\u8d77\u3053\u3059\u53ef\u80fd\u6027\u304c\u3042\u308b\u305f\u3081\u3001\u3053\u306e\u69cb\u9020\u4f53\u306f\u540c\u6642\u306b\u4f7f\u7528\u3055\u308c\u308b\u3079\u304d\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u30022\u756a\u76ee\u306e\u5f71\u97ff\u306f\u3001 \u975e\u52b9\u7387\u306a\u30b9\u30e9\u30a4\u30b9\u306e\u521d\u671f\u5316 (#21) \u3067\u898b\u305f\u3082\u306e\u3067\u3059\u3002\u30b9\u30e9\u30a4\u30b9\u306e\u5c06\u6765\u306e\u9577\u3055\u304c\u3059\u3067\u306b\u308f\u304b\u3063\u3066\u3044\u308b\u5834\u5408\u306f\u3001\u305d\u308c\u3092\u4e8b\u524d\u306b\u5272\u308a\u5f53\u3066\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u305d\u306e\u305f\u3081\u306b\u3001strings.Builder
\u306f\u5225\u306e n
\u30d0\u30a4\u30c8\u306e\u305f\u3081\u306e\u30b9\u30da\u30fc\u30b9\u3092\u4fdd\u8a3c\u3059\u308b\u30e1\u30bd\u30c3\u30c9 Grow(n int)
\u3092\u6301\u3063\u3066\u3044\u307e\u3059\u3002
func concat(values []string) string {\n total := 0\n for i := 0; i < len(values); i++ {\n total += len(values[i])\n }\n\n sb := strings.Builder{}\n sb.Grow(total) (2)\n for _, value := range values {\n _, _ = sb.WriteString(value)\n }\n return sb.String()\n}\n
\u30d9\u30f3\u30c1\u30de\u30fc\u30af\u3092\u5b9f\u884c\u3057\u3066 3 \u3064\u306e\u30d0\u30fc\u30b8\u30e7\u30f3\uff08 +=
\u3092\u4f7f\u7528\u3057\u305f V1 \u3001\u4e8b\u524d\u5272\u308a\u5f53\u3066\u306a\u3057\u3067 strings.Builder{}
\u3092\u4f7f\u7528\u3057\u305f V2 \u3001\u4e8b\u524d\u5272\u308a\u5f53\u3066\u3042\u308a\u306e strings.Builder{}
\u3092\u4f7f\u7528\u3057\u305f V3 \uff09\u3092\u6bd4\u8f03\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002\u5165\u529b\u30b9\u30e9\u30a4\u30b9\u306b\u306f 1,000 \u500b\u306e\u6587\u5b57\u5217\u304c\u542b\u307e\u308c\u3066\u304a\u308a\u3001\u5404\u6587\u5b57\u5217\u306b\u306f 1,000 \u30d0\u30a4\u30c8\u304c\u542b\u307e\u308c\u3066\u3044\u307e\u3059\u3002
BenchmarkConcatV1-4 16 72291485 ns/op\nBenchmarkConcatV2-4 1188 878962 ns/op\nBenchmarkConcatV3-4 5922 190340 ns/op\n
\u3054\u89a7\u306e\u3068\u304a\u308a\u3001\u6700\u65b0\u30d0\u30fc\u30b8\u30e7\u30f3\u304c\u6700\u3082\u52b9\u7387\u7684\u3067\u3001V1 \u3088\u308a 99% \u3001V2 \u3088\u308a 78% \u9ad8\u901f\u3067\u3059\u3002
strings.Builder
\u306f\u3001\u6587\u5b57\u5217\u306e\u30ea\u30b9\u30c8\u3092\u9023\u7d50\u3059\u308b\u305f\u3081\u306e\u89e3\u6c7a\u7b56\u3068\u3057\u3066\u63a8\u5968\u3055\u308c\u307e\u3059\u3002\u901a\u5e38\u3001\u3053\u308c\u306f\u30eb\u30fc\u30d7\u5185\u3067\u4f7f\u7528\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u3044\u304f\u3064\u304b\u306e\u6587\u5b57\u5217 \uff08\u540d\u524d\u3068\u59d3\u306a\u3069\uff09\u3092\u9023\u7d50\u3059\u308b\u3060\u3051\u306e\u5834\u5408\u3001 strings.Builder
\u306e\u4f7f\u7528\u306f\u3001 +=
\u6f14\u7b97\u5b50\u3084 fmt.Sprintf
\u3068\u6bd4\u3079\u3066\u53ef\u8aad\u6027\u304c\u4f4e\u304f\u306a\u308b\u304b\u3089\u3067\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#40","title":"\u7121\u99c4\u306a\u6587\u5b57\u5217\u5909\u63db (#40)","text":"\u8981\u7d04bytes
\u30d1\u30c3\u30b1\u30fc\u30b8\u306f strings
\u30d1\u30c3\u30b1\u30fc\u30b8\u3068\u540c\u3058\u64cd\u4f5c\u3092\u63d0\u4f9b\u3057\u3066\u304f\u308c\u308b\u3053\u3068\u3092\u899a\u3048\u3066\u304a\u304f\u3068\u3001\u4f59\u5206\u306a\u30d0\u30a4\u30c8\u30fb\u6587\u5b57\u5217\u5909\u63db\u3092\u907f\u3051\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002
\u6587\u5b57\u5217\u307e\u305f\u306f []byte
\u3092\u6271\u3046\u3053\u3068\u3092\u9078\u629e\u3059\u308b\u5834\u5408\u3001\u307b\u3068\u3093\u3069\u306e\u30d7\u30ed\u30b0\u30e9\u30de\u30fc\u306f\u5229\u4fbf\u6027\u306e\u305f\u3081\u306b\u6587\u5b57\u5217\u3092\u597d\u3080\u50be\u5411\u304c\u3042\u308a\u307e\u3059\u3002\u3057\u304b\u3057\u3001\u307b\u3068\u3093\u3069\u306e I/O \u306f\u5b9f\u969b\u306b\u306f []byte
\u3067\u884c\u308f\u308c\u307e\u3059\u3002\u305f\u3068\u3048\u3070\u3001io.Reader
\u3001io.Writer
\u3001\u304a\u3088\u3073 io.ReadAll
\u306f\u6587\u5b57\u5217\u3067\u306f\u306a\u304f []byte
\u3092\u51e6\u7406\u3057\u307e\u3059\u3002
\u6587\u5b57\u5217\u3068 []byte
\u306e\u3069\u3061\u3089\u3092\u6271\u3046\u3079\u304d\u304b\u8ff7\u3063\u305f\u3068\u304d\u3001[]byte
\u3092\u6271\u3046\u65b9\u304c\u5fc5\u305a\u3057\u3082\u9762\u5012\u3060\u3068\u3044\u3046\u308f\u3051\u3067\u306f\u306a\u3044\u3053\u3068\u3092\u601d\u3044\u51fa\u3057\u3066\u304f\u3060\u3055\u3044\u3002strings \u30d1\u30c3\u30b1\u30fc\u30b8\u304b\u3089\u30a8\u30af\u30b9\u30dd\u30fc\u30c8\u3055\u308c\u305f\u3059\u3079\u3066\u306e\u95a2\u6570\u306b\u306f\u3001bytes
\u30d1\u30c3\u30b1\u30fc\u30b8\u306b\u4ee3\u66ff\u6a5f\u80fd\u304c\u3042\u308a\u307e\u3059\u3002 Split
\u3001Count
\u3001Contains
\u3001Index
\u306a\u3069\u3067\u3059\u3002\u3057\u305f\u304c\u3063\u3066\u3001I/O \u3092\u5b9f\u884c\u3057\u3066\u3044\u308b\u304b\u3069\u3046\u304b\u306b\u95a2\u4fc2\u306a\u304f\u3001\u6587\u5b57\u5217\u306e\u4ee3\u308f\u308a\u306b\u30d0\u30a4\u30c8\u3092\u4f7f\u7528\u3057\u3066\u30ef\u30fc\u30af\u30d5\u30ed\u30fc\u5168\u4f53\u3092\u5b9f\u88c5\u3067\u304d\u3001\u8ffd\u52a0\u306e\u5909\u63db\u30b3\u30b9\u30c8\u3092\u56de\u907f\u3067\u304d\u308b\u304b\u3069\u3046\u304b\u3092\u6700\u521d\u306b\u78ba\u8a8d\u3057\u307e\u3057\u3087\u3046\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#41","title":"\u90e8\u5206\u6587\u5b57\u5217\u3068\u30e1\u30e2\u30ea\u30ea\u30fc\u30af (#41)","text":"\u8981\u7d04\u90e8\u5206\u6587\u5b57\u5217\u306e\u4ee3\u308f\u308a\u306b\u30b3\u30d4\u30fc\u3092\u4f7f\u7528\u3059\u308b\u3068\u3001\u90e8\u5206\u6587\u5b57\u5217\u64cd\u4f5c\u306b\u3088\u3063\u3066\u8fd4\u3055\u308c\u308b\u6587\u5b57\u5217\u304c\u540c\u3058\u30d0\u30a4\u30c8\u914d\u5217\u306b\u3088\u3063\u3066\u30b5\u30dd\u30fc\u30c8\u3055\u308c\u308b\u305f\u3081\u3001\u30e1\u30e2\u30ea\u30ea\u30fc\u30af\u3092\u9632\u3050\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002
\u30b9\u30e9\u30a4\u30b9\u3068\u30e1\u30e2\u30ea\u30ea\u30fc\u30af (#26) \u3067\u306f\u3001\u30b9\u30e9\u30a4\u30b9\u307e\u305f\u306f\u914d\u5217\u306e\u30b9\u30e9\u30a4\u30b9\u304c\u30e1\u30e2\u30ea\u30ea\u30fc\u30af\u306e\u72b6\u6cc1\u3092\u5f15\u304d\u8d77\u3053\u3059\u53ef\u80fd\u6027\u304c\u3042\u308b\u3053\u3068\u3092\u78ba\u8a8d\u3057\u307e\u3057\u305f\u3002\u3053\u306e\u539f\u5247\u306f\u3001\u6587\u5b57\u5217\u304a\u3088\u3073\u90e8\u5206\u6587\u5b57\u5217\u306e\u64cd\u4f5c\u306b\u3082\u5f53\u3066\u306f\u307e\u308a\u307e\u3059\u3002
Go\u8a00\u8a9e\u3067\u90e8\u5206\u6587\u5b57\u5217\u64cd\u4f5c\u3092\u4f7f\u7528\u3059\u308b\u3068\u304d\u306f\u30012 \u3064\u306e\u3053\u3068\u306b\u7559\u610f\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u307e\u305a\u3001\u63d0\u4f9b\u3055\u308c\u308b\u9593\u9694\u306f\u30eb\u30fc\u30f3\u6570\u3067\u306f\u306a\u304f\u3001\u30d0\u30a4\u30c8\u6570\u306b\u57fa\u3065\u3044\u3066\u3044\u307e\u3059\u3002\u6b21\u306b\u3001\u7d50\u679c\u306e\u90e8\u5206\u6587\u5b57\u5217\u304c\u6700\u521d\u306e\u6587\u5b57\u5217\u3068\u540c\u3058\u30d0\u30c3\u30ad\u30f3\u30b0\u914d\u5217\u3092\u5171\u6709\u3059\u308b\u305f\u3081\u3001\u90e8\u5206\u6587\u5b57\u5217\u64cd\u4f5c\u306b\u3088\u308a\u30e1\u30e2\u30ea\u30ea\u30fc\u30af\u304c\u767a\u751f\u3059\u308b\u53ef\u80fd\u6027\u304c\u3042\u308a\u307e\u3059\u3002\u3053\u308c\u3092\u9632\u3050\u65b9\u6cd5\u306f\u3001\u6587\u5b57\u5217\u306e\u30b3\u30d4\u30fc\u3092\u624b\u52d5\u3067\u5b9f\u884c\u3059\u308b\u304b\u3001Go 1.18 \u304b\u3089\u5b9f\u88c5\u3055\u308c\u3066\u3044\u308b strings.Clone
\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u3067\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#_7","title":"\u95a2\u6570\u3068\u30e1\u30bd\u30c3\u30c9","text":""},{"location":"ja/#42","title":"\u3069\u306e\u578b\u306e\u30ec\u30b7\u30fc\u30d0\u30fc\u3092\u4f7f\u7528\u3059\u308c\u3070\u3088\u3044\u304b\u308f\u304b\u3063\u3066\u3044\u306a\u3044 (#42)","text":"\u8981\u7d04\u5024\u30ec\u30b7\u30fc\u30d0\u30fc\u3068\u30dd\u30a4\u30f3\u30bf\u30ec\u30b7\u30fc\u30d0\u30fc\u306e\u3069\u3061\u3089\u3092\u4f7f\u7528\u3059\u308b\u304b\u306f\u3001\u3069\u306e\u578b\u306a\u306e\u304b\u3001\u5909\u5316\u3055\u305b\u308b\u5fc5\u8981\u304c\u3042\u308b\u304b\u3069\u3046\u304b\u3001\u30b3\u30d4\u30fc\u3067\u304d\u306a\u3044\u30d5\u30a3\u30fc\u30eb\u30c9\u304c\u542b\u307e\u308c\u3066\u3044\u308b\u304b\u3069\u3046\u304b\u3001\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306f\u3069\u308c\u304f\u3089\u3044\u5927\u304d\u3044\u306e\u304b\u3001\u306a\u3069\u306e\u8981\u7d20\u306b\u57fa\u3065\u3044\u3066\u6c7a\u5b9a\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u5206\u304b\u3089\u306a\u3044\u5834\u5408\u306f\u3001\u30dd\u30a4\u30f3\u30bf\u30ec\u30b7\u30fc\u30d0\u3092\u4f7f\u7528\u3057\u3066\u304f\u3060\u3055\u3044\u3002
\u5024\u30ec\u30b7\u30fc\u30d0\u30fc\u3068\u30dd\u30a4\u30f3\u30bf\u30ec\u30b7\u30fc\u30d0\u30fc\u306e\u3069\u3061\u3089\u3092\u9078\u629e\u3059\u308b\u304b\u306f\u3001\u5fc5\u305a\u3057\u3082\u7c21\u5358\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u3002\u9078\u629e\u306b\u5f79\u7acb\u3064\u3044\u304f\u3064\u304b\u306e\u6761\u4ef6\u306b\u3064\u3044\u3066\u8aac\u660e\u3057\u307e\u3057\u3087\u3046\u3002
\u30dd\u30a4\u30f3\u30bf\u30ec\u30b7\u30fc\u30d0\u30fc\u3067\u306a\u3051\u308c\u3070\u306a\u3089\u306a\u3044 \u3068\u304d
type slice []int\n\nfunc (s *slice) add(element int) {\n *s = append(*s, element)\n}\n
\u30dd\u30a4\u30f3\u30bf\u30ec\u30b7\u30fc\u30d0\u30fc\u3067\u3042\u308b\u3079\u304d \u3068\u304d
\u5024\u30ec\u30b7\u30fc\u30d0\u30fc\u3067\u306a\u3051\u308c\u3070\u306a\u3089\u306a\u3044 \u3068\u304d
\u5024\u30ec\u30b7\u30fc\u30d0\u30fc\u3067\u3042\u308b\u3079\u304d \u3068\u304d
time.Time
\u306a\u3069\u306e\u5c0f\u3055\u306a\u914d\u5217\u307e\u305f\u306f\u69cb\u9020\u4f53\u3067\u3001\u53ef\u5909\u30d5\u30a3\u30fc\u30eb\u30c9\u3092\u6301\u305f\u306a\u3044\u5024\u578b\u3067\u3042\u308b\u5834\u5408\u3002 int
\u3001float64
\u3001\u307e\u305f\u306f string
\u306a\u3069\u306e\u57fa\u672c\u578b\u306e\u5834\u5408\u3002 \u3082\u3061\u308d\u3093\u3001\u7279\u6b8a\u306a\u30b1\u30fc\u30b9\u306f\u5e38\u306b\u5b58\u5728\u3059\u308b\u305f\u3081\u3001\u3059\u3079\u3066\u3092\u7db2\u7f85\u3059\u308b\u3053\u3068\u306f\u4e0d\u53ef\u80fd\u3067\u3059\u304c\u3001\u3053\u306e\u30bb\u30af\u30b7\u30e7\u30f3\u306e\u76ee\u6a19\u306f\u3001\u307b\u3068\u3093\u3069\u306e\u30b1\u30fc\u30b9\u3092\u30ab\u30d0\u30fc\u3059\u308b\u305f\u3081\u306e\u30ac\u30a4\u30c0\u30f3\u30b9\u3092\u63d0\u4f9b\u3059\u308b\u3053\u3068\u3067\u3059\u3002\u901a\u5e38\u306f\u3001\u305d\u3046\u3057\u306a\u3044\u6b63\u5f53\u306a\u7406\u7531\u304c\u306a\u3044\u9650\u308a\u3001\u5024\u30ec\u30b7\u30fc\u30d0\u30fc\u3092\u4f7f\u7528\u3057\u3066\u9593\u9055\u3044\u3042\u308a\u307e\u305b\u3093\u3002\u5206\u304b\u3089\u306a\u3044\u5834\u5408\u306f\u3001\u30dd\u30a4\u30f3\u30bf\u30ec\u30b7\u30fc\u30d0\u3092\u4f7f\u7528\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#43","title":"\u540d\u524d\u4ed8\u304d\u7d50\u679c\u30d1\u30e9\u30e1\u30fc\u30bf\u3092\u307e\u3063\u305f\u304f\u4f7f\u7528\u3057\u3066\u3044\u306a\u3044 (#43)","text":"\u8981\u7d04\u540d\u524d\u4ed8\u304d\u7d50\u679c\u30d1\u30e9\u30e1\u30fc\u30bf\u30fc\u306e\u4f7f\u7528\u306f\u3001\u7279\u306b\u8907\u6570\u306e\u7d50\u679c\u30d1\u30e9\u30e1\u30fc\u30bf\u30fc\u304c\u540c\u3058\u578b\u3092\u6301\u3064\u5834\u5408\u3001\u95a2\u6570\u30fb\u30e1\u30bd\u30c3\u30c9\u306e\u8aad\u307f\u3084\u3059\u3055\u3092\u5411\u4e0a\u3055\u305b\u308b\u52b9\u7387\u7684\u306a\u65b9\u6cd5\u3067\u3059\u3002\u5834\u5408\u306b\u3088\u3063\u3066\u306f\u3001\u540d\u524d\u4ed8\u304d\u7d50\u679c\u30d1\u30e9\u30e1\u30fc\u30bf\u306f\u30bc\u30ed\u5024\u306b\u521d\u671f\u5316\u3055\u308c\u308b\u305f\u3081\u3001\u3053\u306e\u65b9\u6cd5\u304c\u4fbf\u5229\u3067\u3059\u3089\u3042\u308b\u3053\u3068\u3082\u3042\u308a\u307e\u3059\u3002\u305f\u3060\u3057\u6f5c\u5728\u7684\u306a\u526f\u4f5c\u7528\u306b\u306f\u6ce8\u610f\u3057\u3066\u304f\u3060\u3055\u3044\u3002
\u95a2\u6570\u307e\u305f\u306f\u30e1\u30bd\u30c3\u30c9\u3067\u30d1\u30e9\u30e1\u30fc\u30bf\u3092\u8fd4\u3059\u3068\u304d\u3001\u3053\u308c\u3089\u306e\u30d1\u30e9\u30e1\u30fc\u30bf\u306b\u540d\u524d\u3092\u4ed8\u3051\u3066\u3001\u901a\u5e38\u306e\u5909\u6570\u3068\u3057\u3066\u4f7f\u7528\u3067\u304d\u307e\u3059\u3002\u7d50\u679c\u30d1\u30e9\u30e1\u30fc\u30bf\u30fc\u306b\u540d\u524d\u3092\u4ed8\u3051\u308b\u3068\u3001\u95a2\u6570\u30fb\u30e1\u30bd\u30c3\u30c9\u306e\u958b\u59cb\u6642\u306b\u305d\u306e\u30d1\u30e9\u30e1\u30fc\u30bf\u30fc\u306f\u30bc\u30ed\u5024\u306b\u521d\u671f\u5316\u3055\u308c\u307e\u3059\u3002\u540d\u524d\u4ed8\u304d\u7d50\u679c\u30d1\u30e9\u30e1\u30fc\u30bf\u3092\u4f7f\u7528\u3059\u308b\u3068\u3001 \u3080\u304d\u51fa\u3057\u306e return \u6587\uff08\u5f15\u6570\u306a\u3057\uff09 \u3092\u547c\u3073\u51fa\u3059\u3053\u3068\u3082\u3067\u304d\u307e\u3059\u3002\u305d\u306e\u5834\u5408\u3001\u7d50\u679c\u30d1\u30e9\u30e1\u30fc\u30bf\u306e\u73fe\u5728\u306e\u5024\u304c\u623b\u308a\u5024\u3068\u3057\u3066\u4f7f\u7528\u3055\u308c\u307e\u3059\u3002
\u4ee5\u4e0b\u306f\u3001\u540d\u524d\u4ed8\u304d\u7d50\u679c\u30d1\u30e9\u30e1\u30fc\u30bf b
\u3092\u7528\u3044\u305f\u4f8b\u3067\u3059\u3002
func f(a int) (b int) {\n b = a\n return\n}\n
\u3053\u306e\u4f8b\u3067\u306f\u3001\u7d50\u679c\u30d1\u30e9\u30e1\u30fc\u30bf\u306b\u540d\u524d b
\u3092\u4ed8\u3051\u3066\u3044\u307e\u3059\u3002\u5f15\u6570\u306a\u3057\u3067 return \u3092\u547c\u3073\u51fa\u3059\u3068\u3001b
\u306e\u73fe\u5728\u306e\u5024\u304c\u8fd4\u3055\u308c\u307e\u3059\u3002
\u5834\u5408\u306b\u3088\u3063\u3066\u306f\u3001\u540d\u524d\u4ed8\u304d\u306e\u7d50\u679c\u30d1\u30e9\u30e1\u30fc\u30bf\u30fc\u306b\u3088\u3063\u3066\u53ef\u8aad\u6027\u304c\u5411\u4e0a\u3059\u308b\u3053\u3068\u3082\u3042\u308a\u307e\u3059\u3002\u305f\u3068\u3048\u3070\u30012 \u3064\u306e\u30d1\u30e9\u30e1\u30fc\u30bf\u30fc\u304c\u540c\u3058\u578b\u3067\u3042\u308b\u5834\u5408\u306a\u3069\u3067\u3059\u3002\u305d\u306e\u4ed6\u306b\u3082\u3001\u5229\u4fbf\u6027\u306e\u305f\u3081\u306b\u7528\u3044\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u3086\u3048\u306b\u3001\u660e\u78ba\u306a\u5229\u70b9\u304c\u3042\u308b\u5834\u5408\u306f\u3001\u614e\u91cd\u306b\u306a\u308a\u306a\u304c\u3089\u3082\u540d\u524d\u4ed8\u304d\u7d50\u679c\u30d1\u30e9\u30e1\u30fc\u30bf\u3092\u4f7f\u7528\u3059\u308b\u3079\u304d\u3067\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#44","title":"\u540d\u524d\u4ed8\u304d\u7d50\u679c\u30d1\u30e9\u30e1\u30fc\u30bf\u306b\u3088\u308b\u4e88\u60f3\u5916\u306e\u526f\u4f5c\u7528 (#44)","text":"\u8981\u7d04#43 \u3092\u53c2\u7167\u3057\u3066\u304f\u3060\u3055\u3044\u3002
\u540d\u524d\u4ed8\u304d\u7d50\u679c\u30d1\u30e9\u30e1\u30fc\u30bf\u304c\u72b6\u6cc1\u306b\u3088\u3063\u3066\u306f\u5f79\u7acb\u3064\u7406\u7531\u306b\u3064\u3044\u3066\u8aac\u660e\u3057\u307e\u3057\u305f\u3002 \u305f\u3060\u3057\u3001\u3053\u308c\u3089\u306f\u30bc\u30ed\u5024\u306b\u521d\u671f\u5316\u3055\u308c\u308b\u305f\u3081\u3001\u5341\u5206\u306b\u6ce8\u610f\u3057\u306a\u3044\u3068\u3001\u8efd\u5fae\u306a\u30d0\u30b0\u304c\u767a\u751f\u3059\u308b\u53ef\u80fd\u6027\u304c\u3042\u308a\u307e\u3059\u3002\u305f\u3068\u3048\u3070\u3001\u3053\u306e\u30b3\u30fc\u30c9\u306f\u3069\u3053\u304c\u9593\u9055\u3063\u3066\u3044\u308b\u3067\u3057\u3087\u3046\u304b\u3002
func (l loc) getCoordinates(ctx context.Context, address string) (\n lat, lng float32, err error) {\n isValid := l.validateAddress(address) (1)\n if !isValid {\n return 0, 0, errors.New(\"invalid address\")\n }\n\n if ctx.Err() != nil { (2)\n return 0, 0, err\n }\n\n // \u5ea7\u6a19\u3092\u53d6\u5f97\u3057\u3066\u8fd4\u3059\n}\n
\u4e00\u77a5\u3057\u305f\u3060\u3051\u3067\u306f\u30a8\u30e9\u30fc\u306f\u660e\u3089\u304b\u3067\u306f\u306a\u3044\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002if ctx.Err() != nil
\u30b9\u30b3\u30fc\u30d7\u3067\u8fd4\u3055\u308c\u308b\u30a8\u30e9\u30fc\u306f err
\u3067\u3059\u3002\u3057\u304b\u3057\u3001err
\u5909\u6570\u306b\u306f\u5024\u3092\u5272\u308a\u5f53\u3066\u3066\u3044\u307e\u305b\u3093\u3002error
\u578b\u306e\u30bc\u30ed\u5024\u3001 nil
\u306b\u5272\u308a\u5f53\u3066\u3089\u308c\u305f\u307e\u307e\u3067\u3059\u3002\u3057\u305f\u304c\u3063\u3066\u3001\u3053\u306e\u30b3\u30fc\u30c9\u306f\u5e38\u306b nil \u30a8\u30e9\u30fc\u3092\u8fd4\u3057\u307e\u3059\u3002
\u540d\u524d\u4ed8\u304d\u7d50\u679c\u30d1\u30e9\u30e1\u30fc\u30bf\u3092\u4f7f\u7528\u3059\u308b\u5834\u5408\u3001\u5404\u30d1\u30e9\u30e1\u30fc\u30bf\u306f\u30bc\u30ed\u5024\u306b\u521d\u671f\u5316\u3055\u308c\u308b\u3053\u3068\u306b\u6ce8\u610f\u3057\u3066\u304f\u3060\u3055\u3044\u3002\u3053\u306e\u30bb\u30af\u30b7\u30e7\u30f3\u3067\u8aac\u660e\u3057\u305f\u3088\u3046\u306b\u3001\u3053\u308c\u306b\u3088\u308a\u3001\u898b\u3064\u3051\u308b\u306e\u304c\u5fc5\u305a\u3057\u3082\u7c21\u5358\u3067\u306f\u306a\u3044\u8efd\u5fae\u306a\u30d0\u30b0\u304c\u767a\u751f\u3059\u308b\u53ef\u80fd\u6027\u304c\u3042\u308a\u307e\u3059\u3002\u3086\u3048\u306b\u3001\u6f5c\u5728\u7684\u306a\u526f\u4f5c\u7528\u3092\u907f\u3051\u308b\u305f\u3081\u306b\u3001\u540d\u524d\u4ed8\u304d\u7d50\u679c\u30d1\u30e9\u30e1\u30fc\u30bf\u30fc\u3092\u4f7f\u7528\u3059\u308b\u3068\u304d\u306f\u6ce8\u610f\u3057\u3066\u304f\u3060\u3055\u3044\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#nil-45","title":"nil \u30ec\u30b7\u30fc\u30d0\u30fc\u3092\u8fd4\u3059 (#45)","text":"\u8981\u7d04\u30a4\u30f3\u30bf\u30d5\u30a7\u30fc\u30b9\u3092\u8fd4\u3059\u3068\u304d\u306f\u3001nil \u30dd\u30a4\u30f3\u30bf\u3092\u8fd4\u3059\u306e\u3067\u306f\u306a\u304f\u3001\u660e\u793a\u7684\u306a nil \u5024\u3092\u8fd4\u3059\u3088\u3046\u306b\u6ce8\u610f\u3057\u3066\u304f\u3060\u3055\u3044\u3002\u305d\u3046\u3057\u306a\u3051\u308c\u3070\u3001\u610f\u56f3\u3057\u306a\u3044\u7d50\u679c\u304c\u767a\u751f\u3057\u3001\u547c\u3073\u51fa\u3057\u5143\u304c nil \u3067\u306f\u306a\u3044\u5024\u3092\u53d7\u3051\u53d6\u308b\u53ef\u80fd\u6027\u304c\u3042\u308a\u307e\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#46","title":"\u95a2\u6570\u5165\u529b\u306b\u30d5\u30a1\u30a4\u30eb\u540d\u3092\u4f7f\u7528\u3057\u3066\u3044\u308b (#46)","text":"\u8981\u7d04\u30d5\u30a1\u30a4\u30eb\u540d\u306e\u4ee3\u308f\u308a\u306b io.Reader
\u578b\u3092\u53d7\u3051\u53d6\u308b\u3088\u3046\u306b\u95a2\u6570\u3092\u8a2d\u8a08\u3059\u308b\u3068\u3001\u95a2\u6570\u306e\u518d\u5229\u7528\u6027\u304c\u5411\u4e0a\u3057\u3001\u30c6\u30b9\u30c8\u304c\u5bb9\u6613\u306b\u306a\u308a\u307e\u3059\u3002
\u30d5\u30a1\u30a4\u30eb\u540d\u3092\u30d5\u30a1\u30a4\u30eb\u304b\u3089\u8aad\u307f\u53d6\u308b\u305f\u3081\u306e\u95a2\u6570\u5165\u529b\u3068\u3057\u3066\u53d7\u3051\u5165\u308c\u308b\u3053\u3068\u306f\u3001\u307b\u3068\u3093\u3069\u306e\u5834\u5408\u3001\u300c\u30b3\u30fc\u30c9\u306e\u81ed\u3044\u300d\u3068\u307f\u306a\u3055\u308c\u308b\u3079\u304d\u3067\u3059\uff08 os.Open
\u306a\u3069\u306e\u7279\u5b9a\u306e\u95a2\u6570\u3092\u9664\u304f\uff09\u3002\u8907\u6570\u306e\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3059\u308b\u3053\u3068\u306b\u306b\u306a\u308b\u304b\u3082\u3057\u308c\u305a\u3001\u5358\u4f53\u30c6\u30b9\u30c8\u304c\u3088\u308a\u8907\u96d1\u306b\u306a\u308b\u53ef\u80fd\u6027\u304c\u3042\u308b\u304b\u3089\u3067\u3059\u3002\u307e\u305f\u3001\u95a2\u6570\u306e\u518d\u5229\u7528\u6027\u3082\u4f4e\u4e0b\u3057\u307e\u3059 \uff08\u305f\u3060\u3057\u3001\u3059\u3079\u3066\u306e\u95a2\u6570\u304c\u518d\u5229\u7528\u3055\u308c\u308b\u308f\u3051\u3067\u306f\u3042\u308a\u307e\u305b\u3093\uff09\u3002 io.Reader
\u30a4\u30f3\u30bf\u30d5\u30a7\u30fc\u30b9\u3092\u4f7f\u7528\u3059\u308b\u3068\u3001\u30c7\u30fc\u30bf\u30bd\u30fc\u30b9\u304c\u62bd\u8c61\u5316\u3055\u308c\u307e\u3059\u3002\u5165\u529b\u304c\u30d5\u30a1\u30a4\u30eb\u3001\u6587\u5b57\u5217\u3001HTTP \u30ea\u30af\u30a8\u30b9\u30c8\u3001gRPC \u30ea\u30af\u30a8\u30b9\u30c8\u306e\u3044\u305a\u308c\u3067\u3042\u308b\u304b\u306b\u95a2\u4fc2\u306a\u304f\u3001\u5b9f\u88c5\u306f\u518d\u5229\u7528\u3067\u304d\u3001\u7c21\u5358\u306b\u30c6\u30b9\u30c8\u3067\u304d\u307e\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#defer-47","title":"defer
\u5f15\u6570\u3068\u30ec\u30b7\u30fc\u30d0\u30fc\u304c\u3069\u306e\u3088\u3046\u306b\u8a55\u4fa1\u3055\u308c\u308b\u304b\u3092\u77e5\u3089\u306a\u3044\uff08\u5f15\u6570\u306e\u8a55\u4fa1\u3001\u30dd\u30a4\u30f3\u30bf\u30fc\u3001\u304a\u3088\u3073\u5024\u30ec\u30b7\u30fc\u30d0\u30fc\uff09 (#47)","text":"\u8981\u7d04 \u30dd\u30a4\u30f3\u30bf\u3092 defer
\u95a2\u6570\u306b\u6e21\u3059\u3053\u3068\u3068\u3001\u547c\u3073\u51fa\u3057\u3092\u30af\u30ed\u30fc\u30b8\u30e3\u5185\u306b\u30e9\u30c3\u30d7\u3059\u308b\u3053\u3068\u304c\u3001\u5f15\u6570\u3068\u30ec\u30b7\u30fc\u30d0\u30fc\u306e\u5373\u6642\u8a55\u4fa1\u3092\u514b\u670d\u3059\u308b\u305f\u3081\u306b\u5b9f\u73fe\u53ef\u80fd\u306a\u89e3\u6c7a\u7b56\u3067\u3059\u3002
defer
\u95a2\u6570\u3067\u306f\u3001\u5f15\u6570\u306f\u3001\u4e0a\u4f4d\u30d6\u30ed\u30c3\u30af\u306e\u95a2\u6570\u304c\u623b\u3063\u3066\u304b\u3089\u3067\u306f\u306a\u304f\u3001\u3059\u3050\u306b\u8a55\u4fa1\u3055\u308c\u307e\u3059\u3002\u305f\u3068\u3048\u3070\u3001\u3053\u306e\u30b3\u30fc\u30c9\u3067\u306f\u3001\u5e38\u306b\u540c\u3058\u30b9\u30c6\u30fc\u30bf\u30b9\u2015\u2015\u7a7a\u306e\u6587\u5b57\u5217\u2015\u2015\u3067 notify
\u3068 incrementCounter
\u3092\u547c\u3073\u51fa\u3057\u307e\u3059\u3002
const (\n StatusSuccess = \"success\"\n StatusErrorFoo = \"error_foo\"\n StatusErrorBar = \"error_bar\"\n)\n\nfunc f() error {\n var status string\n defer notify(status)\n defer incrementCounter(status)\n\n if err := foo(); err != nil {\n status = StatusErrorFoo\n return err\n }\n\n if err := bar(); err != nil {\n status = StatusErrorBar\n return err\n }\n\n status = StatusSuccess <5>\n return nil\n}\n
\u305f\u3057\u304b\u306b\u3001notify(status)
\u3068 incrementCounter(status)
\u3092 defer
\u95a2\u6570\u3068\u3057\u3066\u547c\u3073\u51fa\u3057\u3066\u3044\u307e\u3059\u3002\u3057\u305f\u304c\u3063\u3066\u3001Go\u8a00\u8a9e\u306f\u3001defer \u3092\u4f7f\u7528\u3057\u305f\u6bb5\u968e\u3067 f
\u304c\u30b9\u30c6\u30fc\u30bf\u30b9\u306e\u73fe\u5728\u306e\u5024\u3092\u8fd4\u3059\u3068\u3001\u3053\u308c\u3089\u306e\u547c\u3073\u51fa\u3057\u306e\u5b9f\u884c\u3092\u9045\u3089\u305b\u3001\u7a7a\u306e\u6587\u5b57\u5217\u3092\u6e21\u3057\u307e\u3059\u3002
defer
\u3092\u4f7f\u3044\u7d9a\u3051\u305f\u3044\u5834\u5408\u306e\u4e3b\u306a\u65b9\u6cd5\u306f 2 \u3064\u3042\u308a\u307e\u3059\u3002
\u6700\u521d\u306e\u89e3\u6c7a\u7b56\u306f\u6587\u5b57\u5217\u30dd\u30a4\u30f3\u30bf\u3092\u6e21\u3059\u3053\u3068\u3067\u3059\u3002
func f() error {\n var status string\n defer notify(&status) \n defer incrementCounter(&status)\n\n // \u95a2\u6570\u306e\u305d\u308c\u4ee5\u5916\u306e\u90e8\u5206\u306f\u5909\u66f4\u306a\u3057\n}\n
defer
\u3092\u4f7f\u7528\u3059\u308b\u3068\u3001\u5f15\u6570\uff08\u3053\u3053\u3067\u306f\u30b9\u30c6\u30fc\u30bf\u30b9\u306e\u30a2\u30c9\u30ec\u30b9\uff09\u304c\u3059\u3050\u306b\u8a55\u4fa1\u3055\u308c\u307e\u3059\u3002\u30b9\u30c6\u30fc\u30bf\u30b9\u81ea\u4f53\u306f\u95a2\u6570\u5168\u4f53\u3067\u5909\u66f4\u3055\u308c\u307e\u3059\u304c\u3001\u305d\u306e\u30a2\u30c9\u30ec\u30b9\u306f\u5272\u308a\u5f53\u3066\u306b\u95a2\u4fc2\u306a\u304f\u4e00\u5b9a\u306e\u307e\u307e\u3067\u3059\u3002\u3088\u3063\u3066\u3001notify
\u307e\u305f\u306f incrementCounter
\u304c\u6587\u5b57\u5217\u30dd\u30a4\u30f3\u30bf\u306b\u3088\u3063\u3066\u53c2\u7167\u3055\u308c\u308b\u5024\u3092\u4f7f\u7528\u3059\u308b\u5834\u5408\u3001\u671f\u5f85\u3069\u304a\u308a\u306b\u52d5\u4f5c\u3057\u307e\u3059\u3002\u305f\u3060\u3057\u3001\u3053\u306e\u89e3\u6c7a\u7b56\u3067\u306f 2 \u3064\u306e\u95a2\u6570\u306e\u30b7\u30b0\u30cd\u30c1\u30e3\u3092\u5909\u66f4\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u3001\u305d\u308c\u304c\u5e38\u306b\u53ef\u80fd\u3067\u3042\u308b\u3068\u306f\u9650\u308a\u307e\u305b\u3093\u3002
\u5225\u306e\u89e3\u6c7a\u7b56\u304c\u3042\u308a\u307e\u3059\u2015\u2015\u30af\u30ed\u30fc\u30b8\u30e3\uff08\u672c\u4f53\u306e\u5916\u90e8\u304b\u3089\u5909\u6570\u3092\u53c2\u7167\u3059\u308b\u533f\u540d\u95a2\u6570\u5024\uff09\u3092 defer
\u6587\u3068\u3057\u3066\u547c\u3073\u51fa\u3059\u3053\u3068\u3067\u3059\u3002
func f() error {\n var status string\n defer func() {\n notify(status)\n incrementCounter(status)\n }()\n\n // \u95a2\u6570\u306e\u305d\u308c\u4ee5\u5916\u306e\u90e8\u5206\u306f\u5909\u66f4\u306a\u3057\n}\n
\u3053\u3053\u3067\u306f\u3001notify
\u3068 incrementCounter
\u306e\u4e21\u65b9\u306e\u547c\u3073\u51fa\u3057\u3092\u30af\u30ed\u30fc\u30b8\u30e3\u5185\u306b\u30e9\u30c3\u30d7\u3057\u307e\u3059\u3002\u3053\u306e\u30af\u30ed\u30fc\u30b8\u30e3\u306f\u3001\u672c\u4f53\u306e\u5916\u90e8\u304b\u3089\u30b9\u30c6\u30fc\u30bf\u30b9\u5909\u6570\u3092\u53c2\u7167\u3057\u307e\u3059\u3002\u3086\u3048\u306b\u3001status
\u306f\u3001defer
\u3092\u547c\u3073\u51fa\u3057\u305f\u3068\u304d\u3067\u306f\u306a\u304f\u3001\u30af\u30ed\u30fc\u30b8\u30e3\u304c\u5b9f\u884c\u3055\u308c\u305f\u3068\u304d\u306b\u8a55\u4fa1\u3055\u308c\u307e\u3059\u3002\u3053\u306e\u89e3\u6c7a\u7b56\u306f\u6b63\u3057\u304f\u6a5f\u80fd\u3059\u308b\u4e0a\u306b\u3001\u30b7\u30b0\u30cd\u30c1\u30e3\u3092\u5909\u66f4\u3059\u308b\u305f\u3081\u306b notify
\u3084 incrementCounter
\u3092\u5fc5\u8981\u3068\u3057\u307e\u305b\u3093\u3002
\u3053\u306e\u52d5\u4f5c\u306f\u30e1\u30bd\u30c3\u30c9\u30ec\u30b7\u30fc\u30d0\u30fc\u306b\u3082\u9069\u7528\u3055\u308c\u308b\u3053\u3068\u306b\u3082\u6ce8\u610f\u3057\u3066\u304f\u3060\u3055\u3044\u3002\u30ec\u30b7\u30fc\u30d0\u30fc\u306f\u3059\u3050\u306b\u8a55\u4fa1\u3055\u308c\u307e\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#_8","title":"\u30a8\u30e9\u30fc\u51e6\u7406","text":""},{"location":"ja/#48","title":"\u30d1\u30cb\u30c3\u30af (#48)","text":"\u8981\u7d04panic
\u306e\u4f7f\u7528\u306f\u3001Go\u8a00\u8a9e\u3067\u30a8\u30e9\u30fc\u306b\u5bfe\u51e6\u3059\u308b\u305f\u3081\u306e\u624b\u6bb5\u3067\u3059\u3002\u305f\u3060\u3057\u3001\u3053\u308c\u306f\u56de\u5fa9\u4e0d\u80fd\u306a\u72b6\u6cc1\u3067\u306e\u307f\u4f7f\u7528\u3059\u308b\u3088\u3046\u306b\u3057\u3066\u304f\u3060\u3055\u3044\u3002\u305f\u3068\u3048\u3070\u3001\u30d2\u30e5\u30fc\u30de\u30f3\u30a8\u30e9\u30fc\u3092\u901a\u77e5\u3059\u308b\u5834\u5408\u3084\u3001\u5fc5\u9808\u306e\u4f9d\u5b58\u95a2\u4fc2\u306e\u8aad\u307f\u8fbc\u307f\u306b\u5931\u6557\u3057\u305f\u5834\u5408\u306a\u3069\u3067\u3059\u3002
Go\u8a00\u8a9e\u3067\u306f\u3001panic \u306f\u901a\u5e38\u306e\u6d41\u308c\u3092\u505c\u6b62\u3059\u308b\u7d44\u307f\u8fbc\u307f\u95a2\u6570\u3067\u3059\u3002
func main() {\n fmt.Println(\"a\")\n panic(\"foo\")\n fmt.Println(\"b\")\n}\n
\u3053\u306e\u30b3\u30fc\u30c9\u306f a \u3092\u51fa\u529b\u3057\u3001b \u3092\u51fa\u529b\u3059\u308b\u524d\u306b\u505c\u6b62\u3057\u307e\u3059\u3002
a\npanic: foo\n\ngoroutine 1 [running]:\nmain.main()\n main.go:7 +0xb3\n
panic \u306e\u4f7f\u7528\u306f\u614e\u91cd\u306b\u3059\u3079\u304d\u3067\u3059\u3002\u4ee3\u8868\u7684\u306a\u30b1\u30fc\u30b9\u304c 2 \u3064\u3042\u308a\u30011 \u3064\u306f\u30d2\u30e5\u30fc\u30de\u30f3\u30a8\u30e9\u30fc\u3092\u901a\u77e5\u3059\u308b\u5834\u5408\uff08\u4f8b: sql.Register
\u30c9\u30e9\u30a4\u30d0\u30fc\u304c nil
\u307e\u305f\u306f\u65e2\u306b\u767b\u9332\u3055\u308c\u3066\u3044\u308b\u5834\u5408\u306b panic \u3092\u8d77\u3053\u3057\u307e\u3059\uff09\u3001\u3082\u3046 1 \u3064\u306f\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u304c\u5fc5\u9808\u306e\u4f9d\u5b58\u95a2\u4fc2\u306e\u751f\u6210\u306b\u5931\u6557\u3057\u305f\u5834\u5408\u3067\u3059\u3002\u7d50\u679c\u3068\u3057\u3066\u3001\u4f8b\u5916\u7684\u306b\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u505c\u6b62\u3057\u307e\u3059\u3002\u305d\u308c\u4ee5\u5916\u306e\u307b\u3068\u3093\u3069\u306e\u5834\u5408\u306b\u304a\u3044\u3066\u306f\u3001\u30a8\u30e9\u30fc\u51e6\u7406\u306f\u3001\u6700\u5f8c\u306e\u623b\u308a\u5f15\u6570\u3068\u3057\u3066\u9069\u5207\u306a\u30a8\u30e9\u30fc\u578b\u3092\u8fd4\u3059\u95a2\u6570\u3092\u901a\u3058\u3066\u884c\u3046\u3079\u304d\u3067\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#49","title":"\u30a8\u30e9\u30fc\u3092\u30e9\u30c3\u30d7\u3059\u3079\u304d\u3068\u304d\u3092\u77e5\u3089\u306a\u3044 (#49)","text":"\u8981\u7d04\u30a8\u30e9\u30fc\u3092\u30e9\u30c3\u30d7\u3059\u308b\u3068\u3001\u30a8\u30e9\u30fc\u3092\u30de\u30fc\u30af\u3057\u305f\u308a\u3001\u8ffd\u52a0\u306e\u30b3\u30f3\u30c6\u30ad\u30b9\u30c8\u3092\u63d0\u4f9b\u3057\u305f\u308a\u3067\u304d\u307e\u3059\u3002\u305f\u3060\u3057\u3001\u30a8\u30e9\u30fc\u30e9\u30c3\u30d4\u30f3\u30b0\u306b\u3088\u308a\u3001\u547c\u3073\u51fa\u3057\u5143\u304c\u30bd\u30fc\u30b9\u30a8\u30e9\u30fc\u3092\u5229\u7528\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308b\u305f\u3081\u3001\u6f5c\u5728\u7684\u306a\u7d50\u5408\u304c\u767a\u751f\u3057\u307e\u3059\u3002\u305d\u308c\u3092\u907f\u3051\u305f\u3044\u5834\u5408\u306f\u3001\u30a8\u30e9\u30fc\u30e9\u30c3\u30d4\u30f3\u30b0\u3092\u4f7f\u7528\u3057\u306a\u3044\u3067\u304f\u3060\u3055\u3044\u3002
Go 1.13 \u4ee5\u964d\u3001%w \u30c7\u30a3\u30ec\u30af\u30c6\u30a3\u30d6\u3092\u4f7f\u7528\u3059\u308c\u3070\u7c21\u5358\u306b\u30a8\u30e9\u30fc\u3092\u30e9\u30c3\u30d7\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u3002\u30a8\u30e9\u30fc\u30e9\u30c3\u30d4\u30f3\u30b0\u3068\u306f\u3001\u30bd\u30fc\u30b9\u30a8\u30e9\u30fc\u3082\u4f7f\u7528\u3067\u304d\u308b\u3088\u3046\u306b\u3059\u308b\u30e9\u30c3\u30d1\u30fc\u30b3\u30f3\u30c6\u30ca\u5185\u3067\u30a8\u30e9\u30fc\u3092\u30e9\u30c3\u30d7\u307e\u305f\u306f\u30d1\u30c3\u30af\u3059\u308b\u3053\u3068\u3067\u3059\u3002\u4e00\u822c\u306b\u3001\u30a8\u30e9\u30fc\u30e9\u30c3\u30d4\u30f3\u30b0\u306e\u4e3b\u306a\u4f7f\u7528\u4f8b\u306f\u6b21\u306e 2 \u3064\u3067\u3059\u3002
\u30a8\u30e9\u30fc\u3092\u51e6\u7406\u3059\u308b\u3068\u304d\u3001\u30a8\u30e9\u30fc\u3092\u30e9\u30c3\u30d7\u3059\u308b\u304b\u3069\u3046\u304b\u3092\u6c7a\u5b9a\u3067\u304d\u307e\u3059\u3002\u30e9\u30c3\u30d4\u30f3\u30b0\u3068\u306f\u3001\u30a8\u30e9\u30fc\u306b\u3055\u3089\u306b\u30b3\u30f3\u30c6\u30ad\u30b9\u30c8\u3092\u8ffd\u52a0\u3057\u305f\u308a\u3001\u30a8\u30e9\u30fc\u3092\u7279\u5b9a\u306e\u30bf\u30a4\u30d7\u3068\u3057\u3066\u30de\u30fc\u30af\u3057\u305f\u308a\u3059\u308b\u3053\u3068\u3067\u3059\u3002\u30a8\u30e9\u30fc\u3092\u30de\u30fc\u30af\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u5834\u5408\u306f\u3001\u72ec\u81ea\u306e\u30a8\u30e9\u30fc\u578b\u3092\u4f5c\u6210\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u3067\u3059\u304c\u3001\u65b0\u305f\u306b\u30b3\u30f3\u30c6\u30ad\u30b9\u30c8\u3092\u52a0\u3048\u305f\u3044\u3060\u3051\u306e\u5834\u5408\u306f\u3001\u65b0\u3057\u3044\u30a8\u30e9\u30fc\u578b\u3092\u4f5c\u6210\u3059\u308b\u5fc5\u8981\u304c\u306a\u3044\u305f\u3081\u3001%w \u30c7\u30a3\u30ec\u30af\u30c6\u30a3\u30d6\u3092\u6307\u5b9a\u3057\u3066 fmt.Errorf \u3092\u4f7f\u7528\u3057\u307e\u3057\u3087\u3046\u3002\u305f\u3060\u3057\u3001\u30a8\u30e9\u30fc\u30e9\u30c3\u30d4\u30f3\u30b0\u306b\u3088\u308a\u3001\u547c\u3073\u51fa\u3057\u5143\u304c\u30bd\u30fc\u30b9\u30a8\u30e9\u30fc\u3092\u5229\u7528\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308b\u305f\u3081\u3001\u6f5c\u5728\u7684\u306a\u7d50\u5408\u304c\u751f\u3058\u307e\u3059\u3002\u305d\u308c\u3092\u907f\u3051\u305f\u3044\u5834\u5408\u306f\u3001\u30a8\u30e9\u30fc\u306e\u30e9\u30c3\u30d4\u30f3\u30b0\u3067\u306f\u306a\u304f\u3001\u30a8\u30e9\u30fc\u306e\u5909\u63db\u3092\u4f7f\u7528\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u305f\u3068\u3048\u3070\u3001%v \u30c7\u30a3\u30ec\u30af\u30c6\u30a3\u30d6\u3092\u6307\u5b9a\u3057\u305f fmt.Errorf \u3092\u4f7f\u7528\u3057\u307e\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#50","title":"\u30a8\u30e9\u30fc\u578b\u306e\u4e0d\u6b63\u306a\u6bd4\u8f03 (#50)","text":"\u8981\u7d04Go 1.13 \u306e\u30a8\u30e9\u30fc\u30e9\u30c3\u30d4\u30f3\u30b0\u3092 %w
\u30c7\u30a3\u30ec\u30af\u30c6\u30a3\u30d6\u3068 fmt.Errorf
\u3067\u4f7f\u7528\u3059\u308b\u5834\u5408\u3001\u578b\u306b\u5bfe\u3059\u308b\u30a8\u30e9\u30fc\u306e\u6bd4\u8f03\u306f errors.As
\u3092\u901a\u3058\u3066\u884c\u3046\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u305d\u3046\u3067\u306a\u3051\u308c\u3070\u3001\u8fd4\u3055\u308c\u305f\u30a8\u30e9\u30fc\u304c\u30e9\u30c3\u30d7\u3055\u308c\u3066\u3044\u308b\u5834\u5408\u3001\u8a55\u4fa1\u306b\u5931\u6557\u3057\u307e\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#51","title":"\u30a8\u30e9\u30fc\u5024\u306e\u4e0d\u6b63\u306a\u6bd4\u8f03 (#51)","text":"\u8981\u7d04Go 1.13 \u306e\u30a8\u30e9\u30fc\u30e9\u30c3\u30d4\u30f3\u30b0\u3092 %w
\u30c7\u30a3\u30ec\u30af\u30c6\u30a3\u30d6\u3068 fmt.Errorf
\u3067\u4f7f\u7528\u3059\u308b\u5834\u5408\u3001\u30a8\u30e9\u30fc\u3068\u5024\u306e\u6bd4\u8f03\u306f errors.As
\u3092\u901a\u3058\u3066\u884c\u3046\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u305d\u3046\u3067\u306a\u3051\u308c\u3070\u3001\u8fd4\u3055\u308c\u305f\u30a8\u30e9\u30fc\u304c\u30e9\u30c3\u30d7\u3055\u308c\u3066\u3044\u308b\u5834\u5408\u3001\u8a55\u4fa1\u306b\u5931\u6557\u3057\u307e\u3059\u3002
\u30bb\u30f3\u30c1\u30cd\u30eb\u30a8\u30e9\u30fc\u306f\u30b0\u30ed\u30fc\u30d0\u30eb\u5909\u6570\u3068\u3057\u3066\u5b9a\u7fa9\u3055\u308c\u305f\u30a8\u30e9\u30fc\u306e\u3053\u3068\u3067\u3059\u3002
import \"errors\"\n\nvar ErrFoo = errors.New(\"foo\")\n
\u4e00\u822c\u306b\u3001\u6163\u4f8b\u3068\u3057\u3066 Err
\u3067\u59cb\u3081\u3001\u305d\u306e\u5f8c\u306b\u30a8\u30e9\u30fc\u578b\u3092\u7d9a\u3051\u307e\u3059\u3002\u3053\u3053\u3067\u306f ErrFoo
\u3067\u3059\u3002\u30bb\u30f3\u30c1\u30cd\u30eb\u30a8\u30e9\u30fc\u306f\u3001\u4e88\u671f\u3055\u308c\u308b \u30a8\u30e9\u30fc\u3001\u3064\u307e\u308a\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u304c\u78ba\u8a8d\u3059\u308b\u3053\u3068\u3092\u671f\u5f85\u3059\u308b\u30a8\u30e9\u30fc\u3092\u4f1d\u3048\u307e\u3059\u3002\u4e00\u822c\u7684\u306a\u30ac\u30a4\u30c9\u30e9\u30a4\u30f3\u3068\u3057\u3066 var ErrFoo =errors.New(\"foo\")
\u3002 BarError
\u306f error
\u30a4\u30f3\u30bf\u30d5\u30a7\u30fc\u30b9\u3092\u5b9f\u88c5\u3057\u305f\u4e0a\u3067 type BarError struct { ... }
\u3002 \u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3067 %w
\u30c7\u30a3\u30ec\u30af\u30c6\u30a3\u30d6\u3068 fmt.Errorf
\u3092\u4f7f\u7528\u3057\u3066\u30a8\u30e9\u30fc\u30e9\u30c3\u30d7\u3092\u4f7f\u7528\u3059\u308b\u5834\u5408\u3001\u7279\u5b9a\u306e\u5024\u306b\u5bfe\u3059\u308b\u30a8\u30e9\u30fc\u306e\u30c1\u30a7\u30c3\u30af\u306f ==
\u306e\u4ee3\u308f\u308a\u306b errors.Is
\u3092\u4f7f\u7528\u3057\u3066\u884c\u3044\u307e\u3057\u3087\u3046\u3002\u305d\u308c\u306b\u3088\u3063\u3066\u3001\u30bb\u30f3\u30c1\u30cd\u30eb\u30a8\u30e9\u30fc\u304c\u30e9\u30c3\u30d7\u3055\u308c\u3066\u3044\u308b\u5834\u5408\u3067\u3082\u3001errors.Is
\u306f\u305d\u308c\u3092\u518d\u5e30\u7684\u306b\u30a2\u30f3\u30e9\u30c3\u30d7\u3057\u3001\u30c1\u30a7\u30fc\u30f3\u5185\u306e\u5404\u30a8\u30e9\u30fc\u3092\u63d0\u4f9b\u3055\u308c\u305f\u5024\u3068\u6bd4\u8f03\u3067\u304d\u307e\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#2-52","title":"\u30a8\u30e9\u30fc\u306e 2 \u56de\u51e6\u7406 (#52)","text":"\u8981\u7d04\u307b\u3068\u3093\u3069\u306e\u5834\u5408\u3001\u30a8\u30e9\u30fc\u306f 1 \u56de\u3067\u51e6\u7406\u3055\u308c\u308b\u3079\u304d\u3067\u3059\u3002\u30a8\u30e9\u30fc\u3092\u30ed\u30b0\u306b\u8a18\u9332\u3059\u308b\u3053\u3068\u306f\u3001\u30a8\u30e9\u30fc\u3092\u51e6\u7406\u3059\u308b\u3053\u3068\u3067\u3059\u3002\u3059\u306a\u308f\u3061\u3001\u30ed\u30b0\u306b\u8a18\u9332\u3059\u308b\u304b\u30a8\u30e9\u30fc\u3092\u8fd4\u3059\u304b\u3092\u9078\u629e\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u591a\u304f\u306e\u5834\u5408\u3001\u30a8\u30e9\u30fc\u30e9\u30c3\u30d4\u30f3\u30b0\u306f\u3001\u30a8\u30e9\u30fc\u306b\u8ffd\u52a0\u306e\u30b3\u30f3\u30c6\u30ad\u30b9\u30c8\u3092\u63d0\u4f9b\u3057\u3001\u30bd\u30fc\u30b9\u30a8\u30e9\u30fc\u3092\u8fd4\u3059\u3053\u3068\u304c\u3067\u304d\u308b\u305f\u3081\u3001\u89e3\u6c7a\u7b56\u306b\u306a\u308a\u307e\u3059\u3002
\u30a8\u30e9\u30fc\u3092\u8907\u6570\u56de\u51e6\u7406\u3059\u308b\u3053\u3068\u306f\u3001\u7279\u306bGo\u8a00\u8a9e\u306b\u9650\u3089\u305a\u3001\u958b\u767a\u8005\u304c\u983b\u7e41\u306b\u3084\u3063\u3066\u3057\u307e\u3046\u30df\u30b9\u3067\u3059\u3002\u3053\u308c\u306b\u3088\u308a\u3001\u540c\u3058\u30a8\u30e9\u30fc\u304c\u8907\u6570\u56de\u30ed\u30b0\u306b\u8a18\u9332\u3055\u308c\u3001\u30c7\u30d0\u30c3\u30b0\u304c\u56f0\u96e3\u306b\u306a\u308b\u72b6\u6cc1\u304c\u767a\u751f\u3059\u308b\u53ef\u80fd\u6027\u304c\u3042\u308a\u307e\u3059\u3002
\u30a8\u30e9\u30fc\u51e6\u7406\u306f 1 \u5ea6\u3067\u6e08\u307e\u3059\u3079\u304d\u3060\u3068\u3044\u3046\u3053\u3068\u3092\u899a\u3048\u3066\u304a\u304d\u307e\u3057\u3087\u3046\u3002\u30a8\u30e9\u30fc\u3092\u30ed\u30b0\u306b\u8a18\u9332\u3059\u308b\u3053\u3068\u306f\u3001\u30a8\u30e9\u30fc\u3092\u51e6\u7406\u3059\u308b\u3053\u3068\u3067\u3059\u3002\u3064\u307e\u308a\u3001\u884c\u3046\u3079\u304d\u306f\u3001\u30ed\u30b0\u306b\u8a18\u9332\u3059\u308b\u304b\u3001\u30a8\u30e9\u30fc\u3092\u8fd4\u3059\u304b\u306e\u3069\u3061\u3089\u304b\u3060\u3068\u3044\u3046\u3053\u3068\u3067\u3059\u3002\u3053\u308c\u306b\u3088\u308a\u3001\u30b3\u30fc\u30c9\u304c\u7c21\u7d20\u5316\u3055\u308c\u3001\u30a8\u30e9\u30fc\u306e\u72b6\u6cc1\u306b\u3064\u3044\u3066\u3088\u308a\u9069\u5207\u306a\u6d1e\u5bdf\u304c\u5f97\u3089\u308c\u307e\u3059\u3002\u30a8\u30e9\u30fc\u30e9\u30c3\u30d4\u30f3\u30b0\u306f\u3001\u30bd\u30fc\u30b9\u30a8\u30e9\u30fc\u3092\u4f1d\u3048\u3001\u30a8\u30e9\u30fc\u306b\u30b3\u30f3\u30c6\u30ad\u30b9\u30c8\u3092\u8ffd\u52a0\u3067\u304d\u308b\u305f\u3081\u3001\u6700\u3082\u4f7f\u3044\u52dd\u624b\u306e\u826f\u3044\u624b\u6bb5\u306b\u306a\u308a\u307e\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#53","title":"\u30a8\u30e9\u30fc\u51e6\u7406\u3092\u3057\u306a\u3044 (#53)","text":"\u8981\u7d04\u95a2\u6570\u547c\u3073\u51fa\u3057\u4e2d\u3067\u3042\u3063\u3066\u3082\u3001defer
\u95a2\u6570\u5185\u3067\u3042\u3063\u3066\u3082\u3001\u30a8\u30e9\u30fc\u3092\u7121\u8996\u3059\u308b\u3068\u304d\u306f\u3001\u30d6\u30e9\u30f3\u30af\u8b58\u5225\u5b50\u3092\u4f7f\u7528\u3057\u3066\u660e\u78ba\u306b\u884c\u3046\u3079\u304d\u3067\u3059\u3002\u305d\u3046\u3057\u306a\u3044\u3068\u3001\u5c06\u6765\u306e\u8aad\u307f\u624b\u304c\u305d\u308c\u304c\u610f\u56f3\u7684\u3060\u3063\u305f\u306e\u304b\u3001\u305d\u308c\u3068\u3082\u30df\u30b9\u3060\u3063\u305f\u306e\u304b\u56f0\u60d1\u3059\u308b\u53ef\u80fd\u6027\u304c\u3042\u308a\u307e\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#defer-54","title":"defer
\u30a8\u30e9\u30fc\u3092\u51e6\u7406\u3057\u306a\u3044 (#54)","text":"\u8981\u7d04 \u591a\u304f\u306e\u5834\u5408\u3001defer
\u95a2\u6570\u306b\u3088\u3063\u3066\u8fd4\u3055\u308c\u308b\u30a8\u30e9\u30fc\u3092\u7121\u8996\u3059\u3079\u304d\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u3002\u72b6\u6cc1\u306b\u5fdc\u3058\u3066\u3001\u76f4\u63a5\u51e6\u7406\u3059\u308b\u304b\u3001\u547c\u3073\u51fa\u3057\u5143\u306b\u4f1d\u3048\u307e\u3057\u3087\u3046\u3002\u3053\u308c\u3092\u7121\u8996\u3059\u308b\u5834\u5408\u306f\u3001\u30d6\u30e9\u30f3\u30af\u8b58\u5225\u5b50\u3092\u4f7f\u7528\u3057\u3066\u304f\u3060\u3055\u3044\u3002
\u6b21\u306e\u30b3\u30fc\u30c9\u3092\u8003\u3048\u3066\u307f\u307e\u3057\u3087\u3046\u3002
func f() {\n // ...\n notify() // \u30a8\u30e9\u30fc\u51e6\u7406\u306f\u7701\u7565\u3055\u308c\u3066\u3044\u307e\u3059\n}\n\nfunc notify() error {\n // ...\n}\n
\u4fdd\u5b88\u6027\u306e\u89b3\u70b9\u304b\u3089\u3001\u3053\u306e\u30b3\u30fc\u30c9\u306f\u3044\u304f\u3064\u304b\u306e\u554f\u984c\u3092\u5f15\u304d\u8d77\u3053\u3059\u53ef\u80fd\u6027\u304c\u3042\u308a\u307e\u3059\u3002\u3042\u308b\u4eba\u304c\u3053\u308c\u3092\u8aad\u3080\u3053\u3068\u3092\u8003\u3048\u3066\u307f\u307e\u3059\u3002\u8aad\u307f\u624b\u306f\u3001notify \u304c\u30a8\u30e9\u30fc\u3092\u8fd4\u3059\u306b\u3082\u304b\u304b\u308f\u3089\u305a\u3001\u305d\u306e\u30a8\u30e9\u30fc\u304c\u89aa\u95a2\u6570\u306b\u3088\u3063\u3066\u51e6\u7406\u3055\u308c\u306a\u3044\u3053\u3068\u306b\u6c17\u3065\u304d\u307e\u3059\u3002\u30a8\u30e9\u30fc\u51e6\u7406\u304c\u610f\u56f3\u7684\u3067\u3042\u308b\u304b\u3069\u3046\u304b\u3092\u679c\u305f\u3057\u3066\u63a8\u6e2c\u3067\u304d\u308b\u3067\u3057\u3087\u3046\u304b\u3002\u4ee5\u524d\u306e\u958b\u767a\u8005\u304c\u305d\u308c\u3092\u51e6\u7406\u3059\u308b\u306e\u3092\u5fd8\u308c\u305f\u306e\u304b\u3001\u305d\u308c\u3068\u3082\u610f\u56f3\u7684\u306b\u51e6\u7406\u3057\u305f\u306e\u304b\u3092\u77e5\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u3067\u3057\u3087\u3046\u304b\u3002
\u3053\u308c\u3089\u306e\u7406\u7531\u306b\u3088\u308a\u3001\u30a8\u30e9\u30fc\u3092\u7121\u8996\u3057\u305f\u3044\u5834\u5408\u3001\u30d6\u30e9\u30f3\u30af\u8b58\u5225\u5b50\uff08 _
\uff09\u3092\u4f7f\u3046\u307b\u304b\u3042\u308a\u307e\u305b\u3093\u3002
_ = notify\n
\u30b3\u30f3\u30d1\u30a4\u30eb\u3068\u5b9f\u884c\u6642\u9593\u306e\u70b9\u3067\u306f\u3001\u3053\u306e\u65b9\u6cd5\u306f\u6700\u521d\u306e\u30b3\u30fc\u30c9\u90e8\u5206\u3068\u6bd4\u3079\u3066\u4f55\u3082\u5909\u308f\u308a\u307e\u305b\u3093\u3002\u3057\u304b\u3057\u3001\u3053\u306e\u65b0\u3057\u3044\u30d0\u30fc\u30b8\u30e7\u30f3\u3067\u306f\u3001\u79c1\u305f\u3061\u304c\u30a8\u30e9\u30fc\u306b\u95a2\u5fc3\u304c\u306a\u3044\u3053\u3068\u3092\u660e\u3089\u304b\u306b\u3057\u3066\u3044\u307e\u3059\u3002\u307e\u305f\u3001\u30a8\u30e9\u30fc\u304c\u7121\u8996\u3055\u308c\u308b\u7406\u7531\u3092\u793a\u3059\u30b3\u30e1\u30f3\u30c8\u3092\u8ffd\u52a0\u3059\u308b\u3053\u3068\u3082\u3067\u304d\u307e\u3059\u3002
// \u6700\u5927\u3067\u3082 1 \u56de\u306e\u4f1d\u9054 \n// \u305d\u308c\u3086\u3048\u3001\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u305f\u5834\u5408\u306b\u305d\u308c\u3089\u306e\u4e00\u90e8\u304c\u5931\u308f\u308c\u308b\u3053\u3068\u306f\u8a31\u5bb9\u3055\u308c\u307e\u3059\n_ = notify()\n
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#_9","title":"\u4e26\u884c\u51e6\u7406\uff1a\u57fa\u790e","text":""},{"location":"ja/#55","title":"\u4e26\u884c\u51e6\u7406\u3068\u4e26\u5217\u51e6\u7406\u306e\u6df7\u540c (#55)","text":"\u8981\u7d04\u4e26\u884c\u51e6\u7406\u3068\u4e26\u5217\u51e6\u7406\u306e\u57fa\u672c\u7684\u306a\u9055\u3044\u3092\u7406\u89e3\u3059\u308b\u3053\u3068\u306f\u3001 Go \u958b\u767a\u8005\u306b\u3068\u3063\u3066\u5fc5\u9808\u3067\u3059\u3002\u4e26\u884c\u51e6\u7406\u306f\u69cb\u9020\u306b\u95a2\u3059\u308b\u3082\u306e\u3067\u3059\u304c\u3001\u4e26\u5217\u51e6\u7406\u306f\u5b9f\u884c\u306b\u95a2\u3059\u308b\u3082\u306e\u3067\u3059\u3002
\u4e26\u884c\u51e6\u7406\u3068\u4e26\u5217\u51e6\u7406\u306f\u540c\u3058\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u3002
\u307e\u3068\u3081\u308b\u3068\u3001\u4e26\u884c\u51e6\u7406\u306f\u3001\u4e26\u5217\u5316\u3067\u304d\u308b\u90e8\u5206\u3092\u3082\u3064\u554f\u984c\u3092\u89e3\u6c7a\u3059\u308b\u305f\u3081\u306e\u69cb\u9020\u3092\u63d0\u4f9b\u3057\u307e\u3059\u3002\u3059\u306a\u308f\u3061\u3001\u4e26\u884c\u51e6\u7406\u306b\u3088\u308a\u4e26\u5217\u51e6\u7406\u304c\u53ef\u80fd \u306b\u306a\u308a\u307e\u3059 \u3002
"},{"location":"ja/#56","title":"\u4e26\u884c\u51e6\u7406\u306e\u307b\u3046\u304c\u5e38\u306b\u65e9\u3044\u3068\u8003\u3048\u3066\u3044\u308b (#56)","text":"\u8981\u7d04\u719f\u7df4\u3057\u305f\u958b\u767a\u8005\u306b\u306a\u308b\u306b\u306f\u3001\u4e26\u884c\u51e6\u7406\u304c\u5fc5\u305a\u3057\u3082\u9ad8\u901f\u3067\u3042\u308b\u3068\u306f\u9650\u3089\u306a\u3044\u3053\u3068\u3092\u8a8d\u8b58\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u6700\u5c0f\u9650\u306e\u30ef\u30fc\u30af\u30ed\u30fc\u30c9\u306e\u4e26\u5217\u51e6\u7406\u3092\u4f34\u3046\u89e3\u6c7a\u7b56\u306f\u3001\u5fc5\u305a\u3057\u3082\u9010\u6b21\u51e6\u7406\u3088\u308a\u9ad8\u901f\u3067\u3042\u308b\u3068\u306f\u9650\u308a\u307e\u305b\u3093\u3002\u9010\u6b21\u51e6\u7406\u3068\u4e26\u884c\u51e6\u7406\u306e\u30d9\u30f3\u30c1\u30de\u30fc\u30af\u306f\u3001\u4eee\u5b9a\u3092\u691c\u8a3c\u3059\u308b\u65b9\u6cd5\u3067\u3042\u308b\u3079\u304d\u3067\u3059\u3002
\u30bb\u30af\u30b7\u30e7\u30f3\u5168\u6587\u306f\u3053\u3061\u3089\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#57","title":"\u30c1\u30e3\u30cd\u30eb\u307e\u305f\u306f\u30df\u30e5\u30fc\u30c6\u30c3\u30af\u30b9\u3092\u3044\u3064\u4f7f\u7528\u3059\u308b\u3079\u304d\u304b\u306b\u3064\u3044\u3066\u6238\u60d1\u3063\u3066\u3044\u308b (#57)","text":"\u8981\u7d04\u30b4\u30eb\u30fc\u30c1\u30f3\u306e\u76f8\u4e92\u4f5c\u7528\u3092\u8a8d\u8b58\u3057\u3066\u3044\u308b\u3053\u3068\u306f\u3001\u30c1\u30e3\u30cd\u30eb\u3068\u30df\u30e5\u30fc\u30c6\u30c3\u30af\u30b9\u306e\u3069\u3061\u3089\u3092\u9078\u629e\u3059\u308b\u304b\u3092\u6c7a\u5b9a\u3059\u308b\u3068\u304d\u306b\u3082\u5f79\u7acb\u3061\u307e\u3059\u3002\u4e00\u822c\u306b\u3001\u4e26\u5217\u30b4\u30eb\u30fc\u30c1\u30f3\u306b\u306f\u540c\u671f\u304c\u5fc5\u8981\u3067\u3042\u308a\u3001\u3057\u305f\u304c\u3063\u3066\u30df\u30e5\u30fc\u30c6\u30c3\u30af\u30b9\u304c\u5fc5\u8981\u3067\u3059\u3002\u53cd\u5bfe\u306b\u3001\u4e26\u884c\u30b4\u30eb\u30fc\u30c1\u30f3\u306f\u901a\u5e38\u3001\u8abf\u6574\u3068\u30aa\u30fc\u30b1\u30b9\u30c8\u30ec\u30fc\u30b7\u30e7\u30f3\u3001\u3064\u307e\u308a\u30c1\u30e3\u30cd\u30eb\u3092\u5fc5\u8981\u3068\u3057\u307e\u3059\u3002
\u4e26\u884c\u51e6\u7406\u306e\u554f\u984c\u3092\u8003\u616e\u3059\u308b\u3068\u3001\u30c1\u30e3\u30cd\u30eb\u307e\u305f\u306f\u30df\u30e5\u30fc\u30c6\u30c3\u30af\u30b9\u3092\u4f7f\u7528\u3057\u305f\u89e3\u6c7a\u7b56\u3092\u5b9f\u88c5\u3067\u304d\u308b\u304b\u3069\u3046\u304b\u304c\u5fc5\u305a\u3057\u3082\u660e\u78ba\u3067\u306f\u306a\u3044\u53ef\u80fd\u6027\u304c\u3042\u308a\u307e\u3059\u3002Go\u8a00\u8a9e\u306f\u901a\u4fe1\u306b\u3088\u308b\u30e1\u30e2\u30ea\u306e\u5171\u6709\u3092\u4fc3\u9032\u3059\u308b\u305f\u3081\u3001\u8d77\u3053\u308a\u3046\u308b\u9593\u9055\u3044\u306e\u3046\u3061\u306e\u4e00\u3064\u306f\u3001\u30e6\u30fc\u30b9\u30b1\u30fc\u30b9\u306b\u304b\u304b\u308f\u3089\u305a\u3001\u30c1\u30e3\u30cd\u30eb\u306e\u4f7f\u7528\u3092\u5e38\u306b\u5f37\u5236\u3059\u308b\u3053\u3068\u3067\u3059\u3002\u3057\u304b\u3057\u306a\u304c\u3089\u30012 \u3064\u306e\u65b9\u6cd5\u306f\u88dc\u5b8c\u7684\u306a\u3082\u306e\u3067\u3042\u308b\u3068\u898b\u306a\u3059\u3079\u304d\u3067\u3059\u3002
\u30c1\u30e3\u30cd\u30eb\u307e\u305f\u306f\u30df\u30e5\u30fc\u30c6\u30c3\u30af\u30b9\u306f\u3069\u306e\u3088\u3046\u306a\u5834\u5408\u306b\u4f7f\u7528\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u306e\u3067\u3057\u3087\u3046\u304b\u3002\u6b21\u306e\u56f3\u306e\u4f8b\u3092\u30d0\u30c3\u30af\u30dc\u30fc\u30f3\u3068\u3057\u3066\u4f7f\u7528\u3057\u307e\u3059\u3002\u3053\u306e\u4f8b\u306b\u306f\u3001\u7279\u5b9a\u306e\u95a2\u4fc2\u3092\u6301\u3064 3 \u3064\u306e\u7570\u306a\u308b\u30b4\u30eb\u30fc\u30c1\u30f3\u304c\u3042\u308a\u307e\u3059\u3002
\u539f\u5247\u3068\u3057\u3066\u3001\u4e26\u5217\u30b4\u30eb\u30fc\u30c1\u30f3\u306f\u3001\u30b9\u30e9\u30a4\u30b9\u306a\u3069\u306e\u5171\u6709\u30ea\u30bd\u30fc\u30b9\u306b\u30a2\u30af\u30bb\u30b9\u3057\u305f\u308a\u5909\u66f4\u3057\u305f\u308a\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u5834\u5408\u306a\u3069\u306b\u3001_\u540c\u671f_\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u540c\u671f\u306f\u30df\u30e5\u30fc\u30c6\u30c3\u30af\u30b9\u3067\u306f\u5f37\u5236\u3055\u308c\u307e\u3059\u304c\u3001\u3069\u306e\u30c1\u30e3\u30cd\u30eb\u578b\u3067\u3082\u5f37\u5236\u3055\u308c\u307e\u305b\u3093\uff08\u30d0\u30c3\u30d5\u30a1\u3042\u308a\u30c1\u30e3\u30cd\u30eb\u3092\u9664\u304f\uff09\u3002\u3057\u305f\u304c\u3063\u3066\u3001\u4e00\u822c\u306b\u3001\u4e26\u5217\u30b4\u30eb\u30fc\u30c1\u30f3\u9593\u306e\u540c\u671f\u306f\u30df\u30e5\u30fc\u30c6\u30c3\u30af\u30b9\u3092\u4ecb\u3057\u3066\u9054\u6210\u3055\u308c\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002
\u4e00\u65b9\u3001\u4e00\u822c\u306b\u3001\u4e26\u884c\u30b4\u30eb\u30fc\u30c1\u30f3\u306f \u8abf\u6574\u304a\u3088\u3073\u30aa\u30fc\u30b1\u30b9\u30c8\u30ec\u30fc\u30b7\u30e7\u30f3 \u3092\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u305f\u3068\u3048\u3070\u3001G3 \u304c G1 \u3068 G2 \u306e\u4e21\u65b9\u304b\u3089\u306e\u7d50\u679c\u3092\u96c6\u7d04\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u5834\u5408\u3001G1 \u3068 G2 \u306f\u65b0\u3057\u3044\u4e2d\u9593\u7d50\u679c\u304c\u5229\u7528\u53ef\u80fd\u3067\u3042\u308b\u3053\u3068\u3092 G3 \u306b\u901a\u77e5\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u3053\u306e\u8abf\u6574\u306f\u30b3\u30df\u30e5\u30cb\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u7bc4\u56f2\u3001\u3064\u307e\u308a\u30c1\u30e3\u30cd\u30eb\u306b\u8a72\u5f53\u3057\u307e\u3059\u3002
\u4e26\u884c\u30b4\u30eb\u30fc\u30c1\u30f3\u306b\u95a2\u3057\u3066\u306f\u3001\u30ea\u30bd\u30fc\u30b9\u306e\u6240\u6709\u6a29\u3092\u3042\u308b\u30b9\u30c6\u30c3\u30d7\uff08G1 \u304a\u3088\u3073 G2\uff09\u304b\u3089\u5225\u306e\u30b9\u30c6\u30c3\u30d7\uff08G3\uff09\u306b\u79fb\u7ba1\u3057\u305f\u3044\u5834\u5408\u3082\u3042\u308a\u307e\u3059\u3002\u305f\u3068\u3048\u3070\u3001G1 \u3068 G2 \u306b\u3088\u3063\u3066\u5171\u6709\u30ea\u30bd\u30fc\u30b9\u304c\u8c4a\u304b\u306b\u306a\u3063\u3066\u3044\u308b\u5834\u5408\u3001\u3042\u308b\u6642\u70b9\u3067\u3053\u306e\u30b8\u30e7\u30d6\u306f\u5b8c\u4e86\u3057\u305f\u3068\u898b\u306a\u3055\u308c\u307e\u3059\u3002\u3053\u3053\u3067\u306f\u3001\u30c1\u30e3\u30cd\u30eb\u3092\u4f7f\u7528\u3057\u3066\u3001\u7279\u5b9a\u306e\u30ea\u30bd\u30fc\u30b9\u306e\u6e96\u5099\u304c\u3067\u304d\u3066\u3044\u308b\u3053\u3068\u3092\u901a\u77e5\u3057\u3001\u6240\u6709\u6a29\u306e\u79fb\u8ee2\u3092\u51e6\u7406\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002
\u30df\u30e5\u30fc\u30c6\u30c3\u30af\u30b9\u3068\u30c1\u30e3\u30cd\u30eb\u306b\u306f\u7570\u306a\u308b\u30bb\u30de\u30f3\u30c6\u30a3\u30af\u30b9\u304c\u3042\u308a\u307e\u3059\u3002\u30b9\u30c6\u30fc\u30c8\u3092\u5171\u6709\u3057\u305f\u3044\u3068\u304d\u3001\u307e\u305f\u306f\u5171\u6709\u30ea\u30bd\u30fc\u30b9\u306b\u30a2\u30af\u30bb\u30b9\u3057\u305f\u3044\u3068\u304d\u306f\u3001\u30df\u30e5\u30fc\u30c6\u30c3\u30af\u30b9\u306b\u3088\u3063\u3066\u3053\u306e\u30ea\u30bd\u30fc\u30b9\u3078\u306e\u6392\u4ed6\u7684\u30a2\u30af\u30bb\u30b9\u304c\u4fdd\u8a3c\u3055\u308c\u307e\u3059\u3002\u53cd\u5bfe\u306b\u3001\u30c1\u30e3\u30cd\u30eb\u306f\u30c7\u30fc\u30bf\u306e\u6709\u7121\uff08chan struct{}
\u306e\u6709\u7121\uff09\u306b\u95a2\u4fc2\u306a\u304f\u30b7\u30b0\u30ca\u30eb\u3092\u884c\u3046\u4ed5\u7d44\u307f\u3067\u3059\u3002\u8abf\u6574\u3084\u6240\u6709\u6a29\u306e\u79fb\u8ee2\u306f\u30c1\u30e3\u30cd\u30eb\u3092\u901a\u3058\u3066\u884c\u3046\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u30b4\u30eb\u30fc\u30c1\u30f3\u304c\u4e26\u5217\u304b\u4e26\u884c\u304b\u3092\u77e5\u308b\u3053\u3068\u304c\u91cd\u8981\u3067\u3059\u3002\u4e00\u822c\u306b\u3001\u4e26\u5217\u30b4\u30eb\u30fc\u30c1\u30f3\u306b\u306f\u30df\u30e5\u30fc\u30c6\u30c3\u30af\u30b9\u304c\u5fc5\u8981\u3067\u3001\u4e26\u884c\u30b4\u30eb\u30fc\u30c1\u30f3\u306b\u306f\u30c1\u30e3\u30cd\u30eb\u304c\u5fc5\u8981\u3067\u3059\u3002
\u4e26\u884c\u51e6\u7406\u306b\u719f\u9054\u3059\u308b\u3068\u3044\u3046\u3053\u3068\u306f\u3001\u30c7\u30fc\u30bf\u7af6\u5408\u3068\u7af6\u5408\u72b6\u614b\u304c\u7570\u306a\u308b\u6982\u5ff5\u3067\u3042\u308b\u3053\u3068\u3092\u7406\u89e3\u3059\u308b\u3053\u3068\u3082\u610f\u5473\u3057\u307e\u3059\u3002\u30c7\u30fc\u30bf\u7af6\u5408\u306f\u3001\u8907\u6570\u306e\u30b4\u30eb\u30fc\u30c1\u30f3\u304c\u540c\u3058\u30e1\u30e2\u30ea\u4f4d\u7f6e\u306b\u540c\u6642\u306b\u30a2\u30af\u30bb\u30b9\u3057\u3001\u305d\u306e\u3046\u3061\u306e\u5c11\u306a\u304f\u3068\u3082 1 \u3064\u304c\u66f8\u304d\u8fbc\u307f\u3092\u884c\u3063\u3066\u3044\u308b\u5834\u5408\u306b\u767a\u751f\u3057\u307e\u3059\u3002\u4e00\u65b9\u3001\u30c7\u30fc\u30bf\u7af6\u5408\u304c\u306a\u3044\u3053\u3068\u304c\u5fc5\u305a\u3057\u3082\u6c7a\u5b9a\u7684\u5b9f\u884c\u3092\u610f\u5473\u3059\u308b\u308f\u3051\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u3002\u52d5\u4f5c\u304c\u5236\u5fa1\u3067\u304d\u306a\u3044\u30a4\u30d9\u30f3\u30c8\u306e\u9806\u5e8f\u3084\u30bf\u30a4\u30df\u30f3\u30b0\u306b\u4f9d\u5b58\u3057\u3066\u3044\u308b\u5834\u5408\u3001\u3053\u308c\u306f\u7af6\u5408\u72b6\u614b\u3067\u3059\u3002
\u7af6\u5408\u554f\u984c\u306f\u3001\u30d7\u30ed\u30b0\u30e9\u30de\u30fc\u304c\u76f4\u9762\u3059\u308b\u53ef\u80fd\u6027\u306e\u3042\u308b\u30d0\u30b0\u306e\u4e2d\u3067\u6700\u3082\u56f0\u96e3\u304b\u3064\u6700\u3082\u6f5c\u4f0f\u6027\u306e\u9ad8\u3044\u30d0\u30b0\u306e 1 \u3064\u3068\u306a\u308a\u307e\u3059\u3002Go \u958b\u767a\u8005\u3068\u3057\u3066\u3001\u79c1\u305f\u3061\u306f\u30c7\u30fc\u30bf\u7af6\u5408\u3068\u7af6\u5408\u72b6\u614b\u3001\u305d\u308c\u3089\u304c\u53ca\u307c\u3057\u3046\u308b\u5f71\u97ff\u3001\u304a\u3088\u3073\u305d\u308c\u3089\u3092\u56de\u907f\u3059\u308b\u65b9\u6cd5\u306a\u3069\u306e\u91cd\u8981\u306a\u5074\u9762\u3092\u7406\u89e3\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002
"},{"location":"ja/#_10","title":"\u30c7\u30fc\u30bf\u7af6\u5408","text":"\u30c7\u30fc\u30bf\u7af6\u5408\u306f\u30012 \u3064\u4ee5\u4e0a\u306e\u30b4\u30eb\u30fc\u30c1\u30f3\u304c\u540c\u3058\u30e1\u30e2\u30ea\u4f4d\u7f6e\u306b\u540c\u6642\u306b\u30a2\u30af\u30bb\u30b9\u3057\u3001\u5c11\u306a\u304f\u3068\u3082 1 \u3064\u304c\u66f8\u304d\u8fbc\u307f\u3092\u884c\u3063\u3066\u3044\u308b\u5834\u5408\u306b\u767a\u751f\u3057\u307e\u3059\u3002\u3053\u306e\u5834\u5408\u3001\u5371\u967a\u306a\u7d50\u679c\u304c\u751f\u3058\u308b\u53ef\u80fd\u6027\u304c\u3042\u308a\u307e\u3059\u3002\u3055\u3089\u306b\u60aa\u3044\u3053\u3068\u306b\u3001\u72b6\u6cc1\u306b\u3088\u3063\u3066\u306f\u3001\u30e1\u30e2\u30ea\u4f4d\u7f6e\u306b\u7121\u610f\u5473\u306a\u30d3\u30c3\u30c8\u306e\u7d44\u307f\u5408\u308f\u305b\u3092\u542b\u3080\u5024\u304c\u4fdd\u6301\u3055\u308c\u3066\u3057\u307e\u3046\u53ef\u80fd\u6027\u304c\u3042\u308a\u307e\u3059\u3002
\u3055\u307e\u3056\u307e\u306a\u624b\u6cd5\u3092\u99c6\u4f7f\u3057\u3066\u3001\u30c7\u30fc\u30bf\u7af6\u5408\u306e\u767a\u751f\u3092\u9632\u3050\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u305f\u3068\u3048\u3070
sync/atomic
\u30d1\u30c3\u30b1\u30fc\u30b8\u3092\u4f7f\u7528\u3059\u308b \u5b9f\u884c\u3057\u305f\u3044\u64cd\u4f5c\u306b\u5fdc\u3058\u3066\u3001\u30c7\u30fc\u30bf\u7af6\u5408\u306e\u306a\u3044\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u304c\u5fc5\u305a\u3057\u3082\u6c7a\u5b9a\u7684\u306a\u7d50\u679c\u3092\u610f\u5473\u3059\u308b\u3067\u3057\u3087\u3046\u304b\u3002\u305d\u3046\u3068\u306f\u3044\u3048\u307e\u305b\u3093\u3002
\u7af6\u5408\u72b6\u614b\u306f\u3001\u52d5\u4f5c\u304c\u5236\u5fa1\u3067\u304d\u306a\u3044\u30a4\u30d9\u30f3\u30c8\u306e\u30b7\u30fc\u30b1\u30f3\u30b9\u307e\u305f\u306f\u30bf\u30a4\u30df\u30f3\u30b0\u306b\u4f9d\u5b58\u3059\u308b\u5834\u5408\u306b\u767a\u751f\u3057\u307e\u3059\u3002\u3053\u3053\u3067\u306f\u3001\u30a4\u30d9\u30f3\u30c8\u306e\u30bf\u30a4\u30df\u30f3\u30b0\u304c\u30b4\u30eb\u30fc\u30c1\u30f3\u306e\u5b9f\u884c\u9806\u5e8f\u3067\u3059\u3002
\u307e\u3068\u3081\u308b\u3068\u3001\u4e26\u884c\u51e6\u7406\u306e\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3067\u4f5c\u696d\u3059\u308b\u5834\u5408\u3001\u30c7\u30fc\u30bf\u7af6\u5408\u306f\u7af6\u5408\u72b6\u614b\u3068\u306f\u7570\u306a\u308b\u3053\u3068\u3092\u7406\u89e3\u3059\u308b\u3053\u3068\u304c\u4e0d\u53ef\u6b20\u3067\u3059\u3002\u30c7\u30fc\u30bf\u7af6\u5408\u306f\u3001\u8907\u6570\u306e\u30b4\u30eb\u30fc\u30c1\u30f3\u304c\u540c\u3058\u30e1\u30e2\u30ea\u4f4d\u7f6e\u306b\u540c\u6642\u306b\u30a2\u30af\u30bb\u30b9\u3057\u3001\u305d\u306e\u3046\u3061\u306e\u5c11\u306a\u304f\u3068\u3082 1 \u3064\u304c\u66f8\u304d\u8fbc\u307f\u3092\u884c\u3063\u3066\u3044\u308b\u5834\u5408\u306b\u767a\u751f\u3057\u307e\u3059\u3002\u30c7\u30fc\u30bf\u7af6\u5408\u3068\u306f\u3001\u4e88\u60f3\u5916\u306e\u52d5\u4f5c\u3092\u610f\u5473\u3057\u307e\u3059\u3002\u305f\u3060\u3057\u3001\u30c7\u30fc\u30bf\u7af6\u5408\u306e\u306a\u3044\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u304c\u5fc5\u305a\u3057\u3082\u6c7a\u5b9a\u7684\u306a\u7d50\u679c\u3092\u610f\u5473\u3059\u308b\u308f\u3051\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u3002\u30c7\u30fc\u30bf\u7af6\u5408\u304c\u306a\u304f\u3066\u3082\u3001\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306f\u5236\u5fa1\u3055\u308c\u3066\u3044\u306a\u3044\u30a4\u30d9\u30f3\u30c8\uff08\u30b4\u30eb\u30fc\u30c1\u30f3\u306e\u5b9f\u884c\u3001\u30c1\u30e3\u30cd\u30eb\u3078\u306e\u30e1\u30c3\u30bb\u30fc\u30b8\u306e\u767a\u4fe1\u901f\u5ea6\u3001\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3078\u306e\u547c\u3073\u51fa\u3057\u306e\u7d99\u7d9a\u6642\u9593\u306a\u3069\uff09\u306b\u4f9d\u5b58\u3059\u308b\u6319\u52d5\u3092\u6301\u3064\u3053\u3068\u304c\u3042\u308a\u307e\u3059\u3002\u305d\u306e\u5834\u5408\u306f\u7af6\u5408\u72b6\u614b\u3067\u3059\u3002\u4e26\u884c\u51e6\u7406\u306e\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u8a2d\u8a08\u306b\u719f\u7df4\u3059\u308b\u306b\u306f\u3001\u4e21\u65b9\u306e\u6982\u5ff5\u3092\u7406\u89e3\u3059\u308b\u3053\u3068\u304c\u809d\u8981\u3067\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#59","title":"\u30ef\u30fc\u30af\u30ed\u30fc\u30c9\u30bf\u30a4\u30d7\u3054\u3068\u306e\u4e26\u884c\u51e6\u7406\u306e\u5f71\u97ff\u3092\u7406\u89e3\u3057\u3066\u3044\u306a\u3044 (#59)","text":"\u8981\u7d04\u4e00\u5b9a\u6570\u306e\u30b4\u30eb\u30fc\u30c1\u30f3\u3092\u4f5c\u6210\u3059\u308b\u3068\u304d\u306f\u3001\u30ef\u30fc\u30af\u30ed\u30fc\u30c9\u306e\u30bf\u30a4\u30d7\u3092\u8003\u616e\u3057\u3066\u304f\u3060\u3055\u3044\u3002CPU \u30d0\u30a6\u30f3\u30c9\u306e\u30b4\u30eb\u30fc\u30c1\u30f3\u3092\u4f5c\u6210\u3059\u308b\u3068\u3044\u3046\u3053\u3068\u306f\u3001\u3053\u306e\u6570\u3092 GOMAXPROCS
\u5909\u6570\uff08\u30c7\u30d5\u30a9\u30eb\u30c8\u3067\u306f\u30db\u30b9\u30c8\u4e0a\u306e CPU \u30b3\u30a2\u306e\u6570\u306b\u57fa\u3065\u304f\uff09\u306b\u8fd1\u3065\u3051\u308b\u3053\u3068\u3092\u610f\u5473\u3057\u307e\u3059\u3002I/O \u30d0\u30a6\u30f3\u30c9\u306e\u30b4\u30eb\u30fc\u30c1\u30f3\u306e\u4f5c\u6210\u306f\u3001\u5916\u90e8\u30b7\u30b9\u30c6\u30e0\u306a\u3069\u306e\u4ed6\u306e\u8981\u56e0\u306b\u4f9d\u5b58\u3057\u307e\u3059\u3002
\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u3067\u306f\u3001\u30ef\u30fc\u30af\u30ed\u30fc\u30c9\u306e\u5b9f\u884c\u6642\u9593\u306f\u6b21\u306e\u3044\u305a\u308c\u304b\u306b\u3088\u3063\u3066\u5236\u9650\u3055\u308c\u307e\u3059\u3002
\u3053\u3053\u6570\u5341\u5e74\u3067\u30e1\u30e2\u30ea\u304c\u975e\u5e38\u306b\u5b89\u4fa1\u306b\u306a\u3063\u305f\u3053\u3068\u3092\u8003\u616e\u3059\u308b\u3068\u3001 3 \u3064\u76ee\u306f\u73fe\u5728\u3067\u306f\u6700\u3082\u307e\u308c\u3067\u3059\u3002\u3057\u305f\u304c\u3063\u3066\u3001\u3053\u306e\u30bb\u30af\u30b7\u30e7\u30f3\u3067\u306f\u3001\u6700\u521d\u306e 2 \u3064\u306e\u30ef\u30fc\u30af\u30ed\u30fc\u30c9\u30bf\u30a4\u30d7\u3001CPU \u30d0\u30a6\u30f3\u30c9\u3068 I/O \u30d0\u30a6\u30f3\u30c9\u306b\u7126\u70b9\u3092\u5f53\u3066\u307e\u3059\u3002
\u30ef\u30fc\u30ab\u30fc\u306b\u3088\u3063\u3066\u5b9f\u884c\u3055\u308c\u308b\u30ef\u30fc\u30af\u30ed\u30fc\u30c9\u304c I/O \u30d0\u30a6\u30f3\u30c9\u3067\u3042\u308b\u5834\u5408\u3001\u5024\u306f\u4e3b\u306b\u5916\u90e8\u30b7\u30b9\u30c6\u30e0\u306b\u4f9d\u5b58\u3057\u307e\u3059\u3002\u9006\u306b\u3001\u30ef\u30fc\u30af\u30ed\u30fc\u30c9\u304c CPU \u306b\u4f9d\u5b58\u3057\u3066\u3044\u308b\u5834\u5408\u3001\u30b4\u30eb\u30fc\u30c1\u30f3\u306e\u6700\u9069\u306a\u6570\u306f\u5229\u7528\u53ef\u80fd\u306a CPU \u30b3\u30a2\u306e\u6570\u306b\u8fd1\u304f\u306a\u308a\u307e\u3059\uff08\u30d9\u30b9\u30c8\u30d7\u30e9\u30af\u30c6\u30a3\u30b9\u306f runtime.GOMAXPROCS
\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u3067\u3059\uff09\u3002\u4e26\u884c\u51e6\u7406\u306e\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u8a2d\u8a08\u3059\u308b\u5834\u5408\u3001\u30ef\u30fc\u30af\u30ed\u30fc\u30c9\u306e\u30bf\u30a4\u30d7\uff08 I/O \u3042\u308b\u3044\u306f CPU \uff09\u3092\u77e5\u308b\u3053\u3068\u304c\u91cd\u8981\u3067\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#go-context-60","title":"Go Context \u306b\u5bfe\u3059\u308b\u8aa4\u89e3 (#60)","text":"\u8981\u7d04Go Context \u306f\u3001Go\u8a00\u8a9e\u306e\u4e26\u884c\u51e6\u7406\u306e\u57fa\u790e\u306e\u4e00\u90e8\u3067\u3082\u3042\u308a\u307e\u3059\u3002 Context \u3092\u4f7f\u7528\u3059\u308b\u3068\u3001\u30c7\u30c3\u30c9\u30e9\u30a4\u30f3\u3001\u30ad\u30fc\u3068\u5024\u306e\u30ea\u30b9\u30c8\u3092\u4fdd\u6301\u3067\u304d\u307e\u3059\u3002
https://pkg.go.dev/context
Context \u306f\u3001\u30c7\u30c3\u30c9\u30e9\u30a4\u30f3\u3001\u30ad\u30e3\u30f3\u30bb\u30eb\u30b7\u30b0\u30ca\u30eb\u3001\u305d\u306e\u4ed6\u306e\u5024\u3092 API \u306e\u5883\u754c\u3092\u8d8a\u3048\u3066\u4f1d\u9054\u3057\u307e\u3059\u3002
"},{"location":"ja/#_12","title":"\u30c7\u30c3\u30c9\u30e9\u30a4\u30f3","text":"\u30c7\u30c3\u30c9\u30e9\u30a4\u30f3\u3068\u306f\u3001\u6b21\u306e\u3044\u305a\u308c\u304b\u3067\u6c7a\u5b9a\u3055\u308c\u308b\u7279\u5b9a\u306e\u6642\u70b9\u3092\u6307\u3057\u307e\u3059\u3002
time.Duration
\uff08\u4f8b\uff1a250 ms\uff09time.Time
\uff08\u4f8b\uff1a2023-02-07 00:00:00 UTC\uff09 \u30c7\u30c3\u30c9\u30e9\u30a4\u30f3\u306e\u30bb\u30de\u30f3\u30c6\u30a3\u30af\u30b9\u306f\u3001\u3053\u308c\u3092\u904e\u304e\u305f\u5834\u5408\u306f\u9032\u884c\u4e2d\u306e\u30a2\u30af\u30c6\u30a3\u30d3\u30c6\u30a3\u3092\u505c\u6b62\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u3053\u3068\u3092\u4f1d\u3048\u307e\u3059\u3002\u30a2\u30af\u30c6\u30a3\u30d3\u30c6\u30a3\u3068\u306f\u3001\u305f\u3068\u3048\u3070\u3001\u30c1\u30e3\u30cd\u30eb\u304b\u3089\u306e\u30e1\u30c3\u30bb\u30fc\u30b8\u306e\u53d7\u4fe1\u3092\u5f85\u6a5f\u3057\u3066\u3044\u308b I/O \u30ea\u30af\u30a8\u30b9\u30c8\u3084\u30b4\u30eb\u30fc\u30c1\u30f3\u3067\u3059\u3002
"},{"location":"ja/#_13","title":"\u30ad\u30e3\u30f3\u30bb\u30eb\u30b7\u30b0\u30ca\u30eb","text":"Go Context \u306e\u3082\u3046 1 \u3064\u306e\u4f7f\u7528\u4f8b\u306f\u3001\u30ad\u30e3\u30f3\u30bb\u30eb\u30b7\u30b0\u30ca\u30eb\u3092\u4f1d\u9001\u3059\u308b\u3053\u3068\u3067\u3059\u3002\u5225\u306e\u30b4\u30eb\u30fc\u30c1\u30f3\u5185\u3067 CreateFileWatcher(ctx context.Context, filename string)
\u3092\u547c\u3073\u51fa\u3059\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u4f5c\u6210\u3059\u308b\u3053\u3068\u3092\u60f3\u50cf\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002\u3053\u306e\u95a2\u6570\u306f\u3001\u30d5\u30a1\u30a4\u30eb\u304b\u3089\u8aad\u307f\u53d6\u308a\u3092\u7d9a\u3051\u3066\u66f4\u65b0\u3092\u30ad\u30e3\u30c3\u30c1\u3059\u308b\u7279\u5b9a\u306e\u30d5\u30a1\u30a4\u30eb\u30a6\u30a9\u30c3\u30c1\u30e3\u30fc\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002\u63d0\u4f9b\u3055\u308c\u305f Context \u304c\u671f\u9650\u5207\u308c\u306b\u306a\u308b\u304b\u30ad\u30e3\u30f3\u30bb\u30eb\u3055\u308c\u308b\u3068\u3001\u3053\u306e\u95a2\u6570\u306f\u305d\u308c\u3092\u51e6\u7406\u3057\u3066\u30d5\u30a1\u30a4\u30eb\u8a18\u8ff0\u5b50\u3092\u9589\u3058\u307e\u3059\u3002
Go Context \u306e\u6700\u5f8c\u306e\u4f7f\u7528\u4f8b\u306f\u3001\u30ad\u30fc\u3068\u5024\u306e\u30ea\u30b9\u30c8\u3092\u904b\u3076\u3053\u3068\u3067\u3059\u3002 Context \u306b\u30ad\u30fc\u3068\u5024\u306e\u30ea\u30b9\u30c8\u3092\u542b\u3081\u308b\u610f\u5473\u306f\u4f55\u3067\u3057\u3087\u3046\u304b\u3002Go Context \u306f\u6c4e\u7528\u7684\u3067\u3042\u308b\u305f\u3081\u3001\u4f7f\u7528\u4f8b\u306f\u7121\u9650\u306b\u3042\u308a\u307e\u3059\u3002
\u305f\u3068\u3048\u3070\u3001\u30c8\u30ec\u30fc\u30b9\u3092\u4f7f\u7528\u3059\u308b\u5834\u5408\u3001\u7570\u306a\u308b\u30b5\u30d6\u95a2\u6570\u306e\u9593\u3067\u540c\u3058\u76f8\u95a2 ID \u3092\u5171\u6709\u3057\u305f\u3044\u3053\u3068\u304c\u3042\u308b\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002\u4e00\u90e8\u306e\u958b\u767a\u8005\u306f\u3001\u3053\u306e ID \u3092\u95a2\u6570\u30b7\u30b0\u30cd\u30c1\u30e3\u306e\u4e00\u90e8\u306b\u3059\u308b\u306b\u306f\u3042\u307e\u308a\u306b\u4fb5\u7565\u7684\u3060\u3068\u8003\u3048\u308b\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002\u3053\u306e\u70b9\u306b\u95a2\u3057\u3066\u3001\u4e0e\u3048\u3089\u308c\u305f Context \u306e\u4e00\u90e8\u3068\u3057\u3066\u305d\u308c\u3092\u542b\u3081\u308b\u3053\u3068\u3092\u6c7a\u5b9a\u3059\u308b\u3053\u3068\u3082\u3067\u304d\u307e\u3059\u3002
"},{"location":"ja/#context","title":"Context \u306e\u30ad\u30e3\u30f3\u30bb\u30eb\u3092\u30ad\u30e3\u30c3\u30c1\u3059\u308b","text":"context.Context
\u30bf\u30a4\u30d7\u306f\u3001\u53d7\u4fe1\u5c02\u7528\u306e\u901a\u77e5\u30c1\u30e3\u30cd\u30eb <-chan struct{}
\u3092\u8fd4\u3059 Done
\u30e1\u30bd\u30c3\u30c9\u3092\u30a8\u30af\u30b9\u30dd\u30fc\u30c8\u3057\u307e\u3059\u3002\u3053\u306e\u30c1\u30e3\u30cd\u30eb\u306f\u3001 Context \u306b\u95a2\u9023\u4ed8\u3051\u3089\u308c\u305f\u4f5c\u696d\u3092\u30ad\u30e3\u30f3\u30bb\u30eb\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u5834\u5408\u306b\u9589\u3058\u3089\u308c\u307e\u3059\u3002\u305f\u3068\u3048\u3070
context.WithCancel
\u3067\u4f5c\u6210\u3055\u308c\u305f Context \u306b\u95a2\u9023\u3059\u308b Done \u30c1\u30e3\u30cd\u30eb\u306f\u3001cancel\u95a2\u6570\u304c\u547c\u3073\u51fa\u3055\u308c\u308b\u3068\u9589\u3058\u3089\u308c\u307e\u3059\u3002 context.WithDeadline
\u3067\u4f5c\u6210\u3057\u305f Context \u306b\u95a2\u9023\u3059\u308b Done \u30c1\u30e3\u30cd\u30eb\u306f\u3001\u30c7\u30c3\u30c9\u30e9\u30a4\u30f3\u3092\u904e\u304e\u308b\u3068\u9589\u3058\u3089\u308c\u307e\u3059\u3002 \u6ce8\u610f\u3059\u3079\u304d\u70b9\u306e 1 \u3064\u306f\u3001\u5185\u90e8\u30c1\u30e3\u30cd\u30eb\u306f\u3001\u7279\u5b9a\u306e\u5024\u3092\u53d7\u3051\u53d6\u3063\u305f\u3068\u304d\u3067\u306f\u306a\u304f\u3001 Context \u304c\u30ad\u30e3\u30f3\u30bb\u30eb\u3055\u308c\u305f\u3068\u304d\u3001\u307e\u305f\u306f\u30c7\u30c3\u30c9\u30e9\u30a4\u30f3\u306b\u9054\u3057\u305f\u3068\u304d\u306b\u9589\u3058\u308b\u5fc5\u8981\u304c\u3042\u308b\u3068\u3044\u3046\u3053\u3068\u3067\u3059\u3002\u30c1\u30e3\u30cd\u30eb\u306e\u30af\u30ed\u30fc\u30ba\u306f\u3001\u3059\u3079\u3066\u306e\u6d88\u8cbb\u8005\u30b4\u30eb\u30fc\u30c1\u30f3\u304c\u53d7\u3051\u53d6\u308b\u552f\u4e00\u306e\u30c1\u30e3\u30cd\u30eb\u30a2\u30af\u30b7\u30e7\u30f3\u3067\u3042\u308b\u305f\u3081\u3067\u3059\u3002\u3053\u306e\u3088\u3046\u306b\u3057\u3066\u3001 Context \u304c\u30ad\u30e3\u30f3\u30bb\u30eb\u3055\u308c\u308b\u304b\u3001\u30c7\u30c3\u30c9\u30e9\u30a4\u30f3\u306b\u9054\u3059\u308b\u3068\u3001\u3059\u3079\u3066\u306e\u6d88\u8cbb\u8005\u306b\u901a\u77e5\u304c\u5c4a\u304d\u307e\u3059\u3002
\u307e\u3068\u3081\u308b\u3068\u3001\u719f\u7df4\u3057\u305f Go \u958b\u767a\u8005\u306b\u306a\u308b\u306b\u306f\u3001 Context \u3068\u305d\u306e\u4f7f\u7528\u65b9\u6cd5\u306b\u3064\u3044\u3066\u7406\u89e3\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u539f\u5247\u3068\u3057\u3066\u3001\u30e6\u30fc\u30b6\u30fc\u304c\u5f85\u6a5f\u3055\u305b\u3089\u308c\u308b\u95a2\u6570\u306f Context \u3092\u53d6\u5f97\u3059\u308b\u3079\u304d\u3067\u3059\u3002\u3053\u308c\u306b\u3088\u308a\u3001\u4e0a\u6d41\u306e\u547c\u3073\u51fa\u3057\u5143\u304c\u3053\u306e\u95a2\u6570\u3092\u3044\u3064\u547c\u3073\u51fa\u3059\u304b\u3092\u6c7a\u5b9a\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308b\u304b\u3089\u3067\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#_14","title":"\u4e26\u884c\u51e6\u7406\uff1a\u5b9f\u8df5","text":""},{"location":"ja/#context-61","title":"\u4e0d\u9069\u5207\u306a Context \u3092\u5e83\u3081\u3066\u3057\u307e\u3046 (#61)","text":"\u8981\u7d04Context \u3092\u4f1d\u64ad\u3059\u308b\u969b\u306b\u306f\u3001Context \u3092\u30ad\u30e3\u30f3\u30bb\u30eb\u3067\u304d\u308b\u6761\u4ef6\u3092\u7406\u89e3\u3059\u308b\u3053\u3068\u304c\u91cd\u8981\u3067\u3059\u3002\u305f\u3068\u3048\u3070\u3001\u30ec\u30b9\u30dd\u30f3\u30b9\u304c\u9001\u4fe1\u3055\u308c\u305f\u969b\u306b HTTP \u30cf\u30f3\u30c9\u30e9\u304c Context \u3092\u30ad\u30e3\u30f3\u30bb\u30eb\u3059\u308b\u3068\u304d\u306a\u3069\u3067\u3059\u3002
\u591a\u304f\u306e\u72b6\u6cc1\u3067\u306f\u3001Go Context \u3092\u4f1d\u64ad\u3059\u308b\u3053\u3068\u304c\u63a8\u5968\u3055\u308c\u307e\u3059\u3002\u305f\u3060\u3057\u3001Context \u306e\u4f1d\u64ad\u306b\u3088\u3063\u3066\u8efd\u5fae\u306a\u30d0\u30b0\u304c\u767a\u751f\u3057\u3001\u30b5\u30d6\u95a2\u6570\u304c\u6b63\u3057\u304f\u5b9f\u884c\u3055\u308c\u306a\u304f\u306a\u308b\u5834\u5408\u304c\u3042\u308a\u307e\u3059\u3002
\u6b21\u306e\u4f8b\u3092\u8003\u3048\u3066\u307f\u307e\u3057\u3087\u3046\u3002\u3044\u304f\u3064\u304b\u306e\u30bf\u30b9\u30af\u3092\u5b9f\u884c\u3057\u3066\u30ec\u30b9\u30dd\u30f3\u30b9\u3092\u8fd4\u3059 HTTP \u30cf\u30f3\u30c9\u30e9\u3092\u516c\u958b\u3057\u307e\u3059\u3002\u305f\u3060\u3057\u3001\u30ec\u30b9\u30dd\u30f3\u30b9\u3092\u8fd4\u3059\u76f4\u524d\u306b\u3001\u305d\u308c\u3092 Kafka \u30c8\u30d4\u30c3\u30af\u306b\u9001\u4fe1\u3057\u305f\u3044\u3068\u601d\u3063\u3066\u3044\u307e\u3059\u3002HTTP \u30b3\u30f3\u30b7\u30e5\u30fc\u30de\u306b\u30ec\u30a4\u30c6\u30f3\u30b7\u306e\u70b9\u3067\u30da\u30ca\u30eb\u30c6\u30a3\u3092\u8ab2\u3057\u305f\u304f\u306a\u3044\u306e\u3067\u3001publish \u30a2\u30af\u30b7\u30e7\u30f3\u3092\u65b0\u3057\u3044\u30b4\u30eb\u30fc\u30c1\u30f3\u5185\u3067\u975e\u540c\u671f\u306b\u51e6\u7406\u3057\u305f\u3044\u3068\u8003\u3048\u3066\u3044\u307e\u3059\u3002\u305f\u3068\u3048\u3070\u3001Context \u304c\u30ad\u30e3\u30f3\u30bb\u30eb\u3055\u308c\u305f\u5834\u5408\u306b\u30e1\u30c3\u30bb\u30fc\u30b8\u306e publish \u30a2\u30af\u30b7\u30e7\u30f3\u3092\u4e2d\u65ad\u3067\u304d\u308b\u3088\u3046\u306b\u3001Context \u3092\u53d7\u3051\u5165\u308c\u308b publish
\u95a2\u6570\u3092\u81ea\u7531\u306b\u4f7f\u3048\u308b\u3068\u3057\u307e\u3059\u3002\u53ef\u80fd\u306a\u5b9f\u88c5\u306f\u6b21\u306e\u3068\u304a\u308a\u3067\u3059\u3002
func handler(w http.ResponseWriter, r *http.Request) {\n response, err := doSomeTask(r.Context(), r)\n if err != nil {\n http.Error(w, err.Error(), http.StatusInternalServerError)\n return\n }\n go func() {\n err := publish(r.Context(), response)\n // err \u306e\u51e6\u7406\u3092\u3059\u308b\n }()\n writeResponse(response)\n}\n
\u3053\u306e\u30b3\u30fc\u30c9\u306e\u4f55\u304c\u554f\u984c\u306a\u306e\u3067\u3057\u3087\u3046\u304b\u3002HTTP \u30ea\u30af\u30a8\u30b9\u30c8\u306b\u4ed8\u3055\u308c\u305f Context \u306f\u3001\u3055\u307e\u3056\u307e\u306a\u72b6\u6cc1\u3067\u30ad\u30e3\u30f3\u30bb\u30eb\u3055\u308c\u308b\u53ef\u80fd\u6027\u304c\u3042\u308b\u3053\u3068\u3092\u77e5\u3063\u3066\u304a\u304f\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002
\u6700\u521d\u306e 2 \u3064\u306e\u30b1\u30fc\u30b9\u3067\u306f\u3001\u51e6\u7406\u306f\u304a\u305d\u3089\u304f\u6b63\u3057\u304f\u884c\u308f\u308c\u307e\u3059\u3002\u305f\u3068\u3048\u3070\u3001doSomeTask \u304b\u3089\u30ec\u30b9\u30dd\u30f3\u30b9\u3092\u53d7\u3051\u53d6\u3063\u305f\u3082\u306e\u306e\u3001\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u304c\u63a5\u7d9a\u3092\u9589\u3058\u305f\u5834\u5408\u3001\u30e1\u30c3\u30bb\u30fc\u30b8\u304c publish \u3055\u308c\u306a\u3044\u3088\u3046\u306b\u3001Context \u304c\u65e2\u306b\u30ad\u30e3\u30f3\u30bb\u30eb\u3055\u308c\u305f\u72b6\u614b\u3067 publish \u3092\u547c\u3073\u51fa\u3057\u3066\u3082\u554f\u984c\u306f\u304a\u305d\u3089\u304f\u8d77\u304d\u307e\u305b\u3093\u3002\u3057\u304b\u3057\u3001\u6700\u5f8c\u306e\u30b1\u30fc\u30b9\u306f\u3069\u3046\u3067\u3057\u3087\u3046\u304b\u3002
\u30ec\u30b9\u30dd\u30f3\u30b9\u304c\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u306b\u66f8\u304d\u8fbc\u307e\u308c\u308b\u3068\u3001\u8981\u6c42\u306b\u95a2\u9023\u4ed8\u3051\u3089\u308c\u305f Context \u304c\u30ad\u30e3\u30f3\u30bb\u30eb\u3055\u308c\u307e\u3059\u3002\u3057\u305f\u304c\u3063\u3066\u3001\u7af6\u5408\u72b6\u614b\u306b\u76f4\u9762\u3057\u307e\u3059\u3002
\u5f8c\u8005\u306e\u5834\u5408\u3001HTTP \u30ec\u30b9\u30dd\u30f3\u30b9\u3092\u3059\u3050\u306b\u8fd4\u3059\u306e\u3067\u3001publish \u3092\u547c\u3073\u51fa\u3059\u3068\u30a8\u30e9\u30fc\u304c\u8fd4\u3055\u308c\u307e\u3059\u3002
\u88dc\u8db3Go 1.21 \u304b\u3089\u306f\u3001\u30ad\u30e3\u30f3\u30bb\u30eb\u305b\u305a\u306b\u65b0\u3057\u3044 Context \u3092\u4f5c\u6210\u3059\u308b\u65b9\u6cd5\u304c\u8ffd\u52a0\u3055\u308c\u307e\u3057\u305f\u3002 context.WithoutCancel
\u306f\u3001\u89aa\u304c\u30ad\u30e3\u30f3\u30bb\u30eb\u3055\u308c\u305f\u3068\u304d\u306b\u30ad\u30e3\u30f3\u30bb\u30eb\u3055\u308c\u3066\u3044\u306a\u3044\u89aa\u306e\u30b3\u30d4\u30fc\u3092\u8fd4\u3057\u307e\u3059\u3002
\u307e\u3068\u3081\u308b\u3068\u3001Context \u306e\u4f1d\u64ad\u306f\u614e\u91cd\u306b\u884c\u3046\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#62","title":"\u505c\u6b62\u3059\u3079\u304d\u3068\u304d\u3092\u77e5\u3089\u305a\u306b\u30b4\u30eb\u30fc\u30c1\u30f3\u3092\u958b\u59cb\u3057\u3066\u3057\u307e\u3046 (#62)","text":"\u8981\u7d04\u30ea\u30fc\u30af\u3092\u907f\u3051\u308b\u3053\u3068\u306f\u3001\u30b4\u30eb\u30fc\u30c1\u30f3\u304c\u958b\u59cb\u3055\u308c\u308b\u305f\u3073\u306b\u3001\u6700\u7d42\u7684\u306b\u505c\u6b62\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u3053\u3068\u3092\u610f\u5473\u3057\u307e\u3059\u3002
\u30b4\u30eb\u30fc\u30c1\u30f3\u306f\u7c21\u5358\u306b\u884c\u3046\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u975e\u5e38\u306b\u7c21\u5358\u3067\u3042\u308b\u305f\u3081\u3001\u65b0\u3057\u3044\u30b4\u30eb\u30fc\u30c1\u30f3\u3092\u3044\u3064\u505c\u6b62\u3059\u308b\u304b\u306b\u3064\u3044\u3066\u306e\u8a08\u753b\u3092\u5fc5\u305a\u3057\u3082\u7acb\u3066\u3066\u3044\u306a\u3044\u53ef\u80fd\u6027\u304c\u3042\u308a\u3001\u30ea\u30fc\u30af\u306b\u3064\u306a\u304c\u308b\u3053\u3068\u304c\u3042\u308a\u307e\u3059\u3002\u30b4\u30eb\u30fc\u30c1\u30f3\u3092\u3044\u3064\u505c\u6b62\u3059\u308c\u3070\u3088\u3044\u304b\u308f\u304b\u3089\u306a\u3044\u306e\u306f\u3001Go\u8a00\u8a9e\u3067\u3088\u304f\u3042\u308b\u8a2d\u8a08\u4e0a\u306e\u554f\u984c\u3067\u3042\u308a\u3001\u4e26\u884c\u51e6\u7406\u306b\u304a\u3051\u308b\u30df\u30b9\u3067\u3059\u3002
\u5177\u4f53\u7684\u306a\u4f8b\u306b\u3064\u3044\u3066\u8aac\u660e\u3057\u307e\u3057\u3087\u3046\u3002\u5916\u90e8\u8a2d\u5b9a\uff08\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u63a5\u7d9a\u306a\u3069\u3092\u4f7f\u7528\u3057\u305f\u3082\u306e\u306a\u3069\uff09\u3092\u76e3\u8996\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u8a2d\u8a08\u3057\u307e\u3059\u3002\u307e\u305a\u3001\u6b21\u306e\u3088\u3046\u306a\u5b9f\u88c5\u3092\u3057\u3066\u307f\u307e\u3059\u3002
func main() {\n newWatcher()\n // \u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u5b9f\u884c\u3059\u308b\n}\n\ntype watcher struct { /* \u3044\u304f\u3064\u304b\u306e\u30ea\u30bd\u30fc\u30b9 */ }\n\nfunc newWatcher() {\n w := watcher{}\n go w.watch() // \u5916\u90e8\u8a2d\u5b9a\u3092\u76e3\u8996\u3059\u308b\u30b4\u30eb\u30fc\u30c1\u30f3\u3092\u4f5c\u6210\u3059\u308b\n}\n
\u3053\u306e\u30b3\u30fc\u30c9\u306e\u554f\u984c\u306f\u3001\u30e1\u30a4\u30f3\u306e\u30b4\u30eb\u30fc\u30c1\u30f3\u304c\u7d42\u4e86\u3059\u308b\u3068\uff08\u304a\u305d\u3089\u304f OS \u30b7\u30b0\u30ca\u30eb\u307e\u305f\u306f\u6709\u9650\u306e\u30ef\u30fc\u30af\u30ed\u30fc\u30c9\u306e\u305f\u3081\uff09\u3001\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u304c\u505c\u6b62\u3057\u3066\u3057\u307e\u3046\u3053\u3068\u3067\u3059\u3002\u3057\u305f\u304c\u3063\u3066\u3001\u30a6\u30a9\u30c3\u30c1\u30e3\u30fc\u306b\u3088\u3063\u3066\u4f5c\u6210\u3055\u308c\u305f\u30ea\u30bd\u30fc\u30b9\u306f\u6b63\u5e38\u306b\u9589\u3058\u3089\u308c\u307e\u305b\u3093\u3002\u3053\u308c\u3092\u9632\u3050\u306b\u306f\u3069\u3046\u3059\u308c\u3070\u3088\u3044\u3067\u3057\u3087\u3046\u304b\u3002
1 \u3064\u306e\u65b9\u6cd5\u3068\u3057\u3066\u306f\u3001main \u304c\u623b\u3063\u305f\u3068\u304d\u306b\u30ad\u30e3\u30f3\u30bb\u30eb\u3055\u308c\u308b Context \u3092 newWatcher \u306b\u6e21\u3059\u3053\u3068\u304c\u6319\u3052\u3089\u308c\u307e\u3059\u3002
func main() {\n ctx, cancel := context.WithCancel(context.Background())\n defer cancel()\n newWatcher(ctx)\n // \u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u5b9f\u884c\u3059\u308b\n}\n\nfunc newWatcher(ctx context.Context) {\n w := watcher{}\n go w.watch(ctx)\n}\n
\u4f5c\u6210\u3057\u305f Context \u3092 watch \u30e1\u30bd\u30c3\u30c9\u306b\u4f1d\u64ad\u3057\u307e\u3059\u3002Context \u304c\u30ad\u30e3\u30f3\u30bb\u30eb\u3055\u308c\u308b\u3068\u3001\u30a6\u30a9\u30c3\u30c1\u30e3\u30fc\u69cb\u9020\u4f53\u306f\u305d\u306e\u30ea\u30bd\u30fc\u30b9\u3092\u9589\u3058\u307e\u3059\u3002\u3057\u304b\u3057\u3001watch \u304c\u305d\u308c\u3092\u884c\u3046\u6642\u9593\u304c\u78ba\u5b9f\u306b\u3042\u308b\u3068\u306f\u3044\u3048\u307e\u305b\u3093\u3002\u3053\u308c\u306f\u8a2d\u8a08\u4e0a\u306e\u6b20\u9665\u3067\u3059\u3002
\u554f\u984c\u306f\u3001\u30b4\u30eb\u30fc\u30c1\u30f3\u3092\u505c\u6b62\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u3053\u3068\u3092\u4f1d\u3048\u308b\u305f\u3081\u306b\u30b7\u30b0\u30ca\u30eb\u3092\u4f7f\u7528\u3057\u305f\u3053\u3068\u3067\u3059\u3002\u30ea\u30bd\u30fc\u30b9\u304c\u9589\u3058\u3089\u308c\u308b\u307e\u3067\u3001\u89aa\u306e\u30b4\u30eb\u30fc\u30c1\u30f3\u3092\u30d6\u30ed\u30c3\u30af\u3057\u307e\u305b\u3093\u3067\u3057\u305f\u3002\u305d\u3046\u306a\u3089\u306a\u3044\u3088\u3046\u306b\u3057\u307e\u3057\u3087\u3046\u3002
func main() {\n w := newWatcher()\n defer w.close()\n // \u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u5b9f\u884c\u3059\u308b\n}\n\nfunc newWatcher() watcher {\n w := watcher{}\n go w.watch()\n return w\n}\n\nfunc (w watcher) close() {\n // \u30ea\u30bd\u30fc\u30b9\u3092\u9589\u3058\u308b\n}\n
\u30ea\u30bd\u30fc\u30b9\u3092\u9589\u3058\u308b\u6642\u9593\u306b\u306a\u3063\u305f\u3053\u3068\u3092 watcher
\u306b\u901a\u77e5\u3059\u308b\u4ee3\u308f\u308a\u306b\u3001 defer
\u3092\u4f7f\u7528\u3057\u3066\u3053\u306e\u3000close
\u30e1\u30bd\u30c3\u30c9\u3092\u547c\u3073\u51fa\u3057\u3001\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u304c\u7d42\u4e86\u3059\u308b\u524d\u306b\u30ea\u30bd\u30fc\u30b9\u304c\u78ba\u5b9f\u306b\u9589\u3058\u3089\u308c\u308b\u3088\u3046\u306b\u3057\u307e\u3059\u3002
\u307e\u3068\u3081\u308b\u3068\u3001\u30b4\u30eb\u30fc\u30c1\u30f3\u306f\u4ed6\u306e\u30ea\u30bd\u30fc\u30b9\u3068\u540c\u69d8\u3001\u30e1\u30e2\u30ea\u3084\u4ed6\u306e\u30ea\u30bd\u30fc\u30b9\u3092\u89e3\u653e\u3059\u308b\u305f\u3081\u306b\u6700\u7d42\u7684\u306b\u9589\u3058\u308b\u5fc5\u8981\u304c\u3042\u308b\u3053\u3068\u306b\u6ce8\u610f\u3057\u3066\u304f\u3060\u3055\u3044\u3002\u30b4\u30eb\u30fc\u30c1\u30f3\u3092\u3044\u3064\u505c\u6b62\u3059\u308b\u304b\u3092\u77e5\u3089\u305a\u306b\u958b\u59cb\u3059\u308b\u306e\u306f\u8a2d\u8a08\u4e0a\u306e\u554f\u984c\u3067\u3059\u3002\u30b4\u30eb\u30fc\u30c1\u30f3\u304c\u958b\u59cb\u3055\u308c\u308b\u3068\u304d\u306f\u5e38\u306b\u3001\u3044\u3064\u505c\u6b62\u3059\u308b\u304b\u306b\u3064\u3044\u3066\u660e\u78ba\u306a\u8a08\u753b\u3092\u7acb\u3066\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u6700\u5f8c\u306b\u306a\u308a\u307e\u3057\u305f\u304c\u3001\u30b4\u30eb\u30fc\u30c1\u30f3\u304c\u30ea\u30bd\u30fc\u30b9\u3092\u4f5c\u6210\u3057\u3001\u305d\u306e\u6709\u52b9\u671f\u9593\u304c\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u5b58\u7d9a\u671f\u9593\u306b\u30d0\u30a4\u30f3\u30c9\u3055\u308c\u3066\u3044\u308b\u5834\u5408\u306f\u3001\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u7d42\u4e86\u3059\u308b\u524d\u306b\u305d\u306e\u30b4\u30eb\u30fc\u30c1\u30f3\u304c\u5b8c\u4e86\u3059\u308b\u306e\u3092\u5f85\u3063\u305f\u65b9\u304c\u304a\u305d\u3089\u304f\u78ba\u5b9f\u3067\u3059\u3002\u305d\u3046\u3059\u308b\u3053\u3068\u3067\u3001\u30ea\u30bd\u30fc\u30b9\u3092\u9593\u9055\u3044\u306a\u304f\u89e3\u653e\u3067\u304d\u307e\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#63","title":"\u30b4\u30eb\u30fc\u30c1\u30f3\u3068\u30eb\u30fc\u30d7\u5909\u6570\u306b\u6ce8\u610f\u3057\u306a\u3044 (#63)","text":"\u6ce8\u610f\u3053\u306e\u30df\u30b9\u306f Go\u30001.22 \u304b\u3089\u306f\u6c17\u306b\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u305b\u3093\uff08\u8a73\u7d30\uff09\u3002
"},{"location":"ja/#select-64","title":"select
\u3068\u30c1\u30e3\u30cd\u30eb\u3092\u4f7f\u7528\u3057\u3066\u6c7a\u5b9a\u7684\u52d5\u4f5c\u3092\u671f\u5f85\u3059\u308b (#64)","text":"\u8981\u7d04 \u8907\u6570\u306e\u30aa\u30d7\u30b7\u30e7\u30f3\u304c\u53ef\u80fd\u306a\u5834\u5408\u3001\u8907\u6570\u306e\u30c1\u30e3\u30cd\u30eb\u3067 select
\u3059\u308b\u3068\u30b1\u30fc\u30b9\u304c\u30e9\u30f3\u30c0\u30e0\u306b\u9078\u629e\u3055\u308c\u308b\u3053\u3068\u3092\u7406\u89e3\u3059\u308b\u3068\u3001\u4e26\u884c\u51e6\u7406\u306b\u304a\u3051\u308b\u8efd\u5fae\u306a\u30d0\u30b0\u306b\u3064\u306a\u304c\u308b\u53ef\u80fd\u6027\u306e\u3042\u308b\u8aa4\u3063\u305f\u4eee\u5b9a\u3092\u7acb\u3066\u308b\u3053\u3068\u304c\u306a\u304f\u306a\u308a\u307e\u3059\u3002
Go \u958b\u767a\u8005\u304c\u30c1\u30e3\u30cd\u30eb\u3092\u64cd\u4f5c\u3059\u308b\u3068\u304d\u306b\u3042\u308a\u304c\u3061\u306a\u9593\u9055\u3044\u306e 1 \u3064\u306f\u3001select \u304c\u8907\u6570\u306e\u30c1\u30e3\u30cd\u30eb\u3067\u3069\u306e\u3088\u3046\u306b\u52d5\u4f5c\u3059\u308b\u304b\u306b\u3064\u3044\u3066\u8aa4\u3063\u305f\u7406\u89e3\u3092\u3059\u308b\u3053\u3068\u3067\u3059\u3002
\u305f\u3068\u3048\u3070\u3001\u6b21\u306e\u5834\u5408\u3092\u8003\u3048\u3066\u307f\u307e\u3057\u3087\u3046\uff08 disconnectCh
\u306f\u30d0\u30c3\u30d5\u30a1\u306a\u3057\u30c1\u30e3\u30cd\u30eb\u3067\u3059\uff09\u3002
go func() {\n for i := 0; i < 10; i++ {\n messageCh <- i\n }\n disconnectCh <- struct{}{}\n}()\n\nfor {\n select {\n case v := <-messageCh:\n fmt.Println(v)\n case <-disconnectCh:\n fmt.Println(\"disconnection, return\")\n return\n }\n}\n
\u3053\u306e\u4f8b\u3092\u8907\u6570\u56de\u5b9f\u884c\u3057\u305f\u5834\u5408\u3001\u7d50\u679c\u306f\u30e9\u30f3\u30c0\u30e0\u306b\u306a\u308a\u307e\u3059\u3002
0\n1\n2\ndisconnection, return\n\n0\ndisconnection, return\n
\u3069\u3046\u3044\u3046\u308f\u3051\u304b 10 \u901a\u306e\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u6d88\u8cbb\u3059\u308b\u306e\u3067\u306f\u306a\u304f\u3001\u305d\u306e\u3046\u3061\u306e\u6570\u901a\u3060\u3051\u3092\u53d7\u4fe1\u3057\u307e\u3057\u305f\u3002\u3053\u308c\u306f\u3001\u8907\u6570\u306e\u30c1\u30e3\u30cd\u30eb\u3068\u4f75\u7528\u3057\u305f\u5834\u5408\u306e select \u6587\u306e\u4ed5\u69d8\u306b\u3088\u308b\u3082\u306e\u3067\u3059\uff08https:// go.dev/ref/spec\uff09\u3002
Quote
1 \u3064\u4ee5\u4e0a\u306e\u901a\u4fe1\u3092\u7d9a\u884c\u3067\u304d\u308b\u5834\u5408\u3001\u5747\u4e00\u306e\u64ec\u4f3c\u30e9\u30f3\u30c0\u30e0\u9078\u629e\u306b\u3088\u3063\u3066\u3001\u7d9a\u884c\u3067\u304d\u308b 1 \u3064\u306e\u901a\u4fe1\u304c\u9078\u629e\u3055\u308c\u307e\u3059\u3002
\u6700\u521d\u306b\u4e00\u81f4\u3057\u305f\u30b1\u30fc\u30b9\u304c\u512a\u5148\u3055\u308c\u308b switch \u6587\u3068\u306f\u7570\u306a\u308a\u3001select \u6587\u306f\u8907\u6570\u306e\u30aa\u30d7\u30b7\u30e7\u30f3\u304c\u53ef\u80fd\u306a\u5834\u5408\u306b\u30e9\u30f3\u30c0\u30e0\u306b\u9078\u629e\u3057\u307e\u3059\u3002
\u3053\u306e\u52d5\u4f5c\u306f\u6700\u521d\u306f\u5947\u5999\u306b\u601d\u3048\u308b\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002\u3057\u304b\u3057\u3001\u3053\u308c\u306f\u30b9\u30bf\u30d9\u30fc\u30b7\u30e7\u30f3\u3092\u9632\u3050\u3068\u3044\u3046\u7406\u7531\u304c\u3042\u3063\u3066\u306e\u3053\u3068\u3067\u3059\u3002\u6700\u521d\u306b\u9078\u629e\u3055\u308c\u305f\u901a\u4fe1\u304c\u30bd\u30fc\u30b9\u306e\u9806\u5e8f\u306b\u57fa\u3065\u3044\u3066\u3044\u308b\u3068\u3057\u307e\u3059\u3002\u305d\u306e\u5834\u5408\u3001\u9001\u4fe1\u901f\u5ea6\u304c\u901f\u3044\u305f\u3081\u306b\u3001\u305f\u3068\u3048\u3070 1 \u3064\u306e\u30c1\u30e3\u30cd\u30eb\u304b\u3089\u3057\u304b\u53d7\u4fe1\u3067\u304d\u306a\u3044\u3068\u3044\u3046\u72b6\u6cc1\u306b\u9665\u308b\u53ef\u80fd\u6027\u304c\u3042\u308a\u307e\u3059\u3002\u3053\u308c\u3092\u9632\u3050\u305f\u3081\u306b\u3001Go\u8a00\u8a9e\u306e\u8a2d\u8a08\u8005\u306f\u30e9\u30f3\u30c0\u30e0\u9078\u629e\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u306b\u3057\u307e\u3057\u305f\u3002
\u8907\u6570\u306e\u30c1\u30e3\u30cd\u30eb\u3067 select
\u3092\u4f7f\u7528\u3059\u308b\u5834\u5408\u3001\u8907\u6570\u306e\u30aa\u30d7\u30b7\u30e7\u30f3\u304c\u3042\u308b\u306a\u3089\u3001\u30bd\u30fc\u30b9\u9806\u5e8f\u306e\u6700\u521d\u306e\u30b1\u30fc\u30b9\u304c\u81ea\u52d5\u7684\u306b\u512a\u5148\u3055\u308c\u308b\u308f\u3051\u3067\u306f\u306a\u3044\u3053\u3068\u306b\u6ce8\u610f\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u4ee3\u308f\u308a\u306b\u3001Go\u8a00\u8a9e\u306f\u30e9\u30f3\u30c0\u30e0\u306b\u9078\u629e\u3059\u308b\u305f\u3081\u3001\u3069\u306e\u30aa\u30d7\u30b7\u30e7\u30f3\u304c\u9078\u629e\u3055\u308c\u308b\u304b\u306f\u4fdd\u8a3c\u3055\u308c\u307e\u305b\u3093\u3002\u3053\u306e\u52d5\u4f5c\u3092\u514b\u670d\u3059\u308b\u306b\u306f\u3001\u5358\u4e00\u306e\u751f\u7523\u8005\u30b4\u30eb\u30fc\u30c1\u30f3\u306e\u5834\u5408\u3001\u30d0\u30c3\u30d5\u30a1\u306a\u3057\u306e\u30c1\u30e3\u30cd\u30eb\u307e\u305f\u306f\u5358\u4e00\u306e\u30c1\u30e3\u30cd\u30eb\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#65","title":"\u901a\u77e5\u30c1\u30e3\u30cd\u30eb\u3092\u4f7f\u7528\u3057\u3066\u3044\u306a\u3044 (#65)","text":"\u8981\u7d04chan struct{}
\u578b\u3092\u4f7f\u7528\u3057\u3066\u901a\u77e5\u3092\u9001\u4fe1\u3057\u307e\u3057\u3087\u3046\u3002
\u30c1\u30e3\u30cd\u30eb\u306f\u3001\u30b7\u30b0\u30ca\u30eb\u3092\u4ecb\u3057\u3066\u30b4\u30eb\u30fc\u30c1\u30f3\u9593\u3067\u901a\u4fe1\u3059\u308b\u305f\u3081\u306e\u30e1\u30ab\u30cb\u30ba\u30e0\u3067\u3059\u3002\u30b7\u30b0\u30ca\u30eb\u306b\u306f\u30c7\u30fc\u30bf\u304c\u542b\u307e\u308c\u3066\u3044\u308b\u304b\u3069\u3046\u304b\u306f\u95a2\u4fc2\u3042\u308a\u307e\u305b\u3093\u3002
\u5177\u4f53\u7684\u306a\u4f8b\u3092\u898b\u3066\u307f\u307e\u3057\u3087\u3046\u3002\u901a\u4fe1\u306e\u5207\u65ad\u304c\u767a\u751f\u3059\u308b\u305f\u3073\u306b\u305d\u308c\u3092\u901a\u77e5\u3059\u308b\u30c1\u30e3\u30cd\u30eb\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002 1 \u3064\u306e\u65b9\u6cd5\u3068\u3057\u3066\u3001\u3053\u308c\u3092 chan bool
\u3068\u3057\u3066\u6271\u3046\u3053\u3068\u304c\u6319\u3052\u3089\u308c\u307e\u3059\u3002
disconnectCh := make(chan bool)\n
\u3053\u3053\u3067\u3001\u305d\u306e\u3088\u3046\u306a\u30c1\u30e3\u30cd\u30eb\u3092\u63d0\u4f9b\u3059\u308b API \u3068\u5bfe\u8a71\u3059\u308b\u3068\u3057\u307e\u3059\u3002\u3053\u308c\u306f\u771f\u507d\u5024\u306e\u30c1\u30e3\u30cd\u30eb\u3067\u3042\u308b\u305f\u3081\u3001true
\u307e\u305f\u306f false
\u306e\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u53d7\u4fe1\u3067\u304d\u307e\u3059\u3002true
\u304c\u4f55\u3092\u4f1d\u3048\u3066\u3044\u308b\u304b\u306f\u304a\u305d\u3089\u304f\u660e\u3089\u304b\u3067\u3057\u3087\u3046\u3002\u3057\u304b\u3057\u3001 false
\u3068\u306f\u4f55\u3092\u610f\u5473\u3059\u308b\u306e\u3067\u3057\u3087\u3046\u304b\u3002\u901a\u4fe1\u304c\u5207\u65ad\u3055\u308c\u3066\u3044\u306a\u3044\u3068\u3044\u3046\u3053\u3068\u3067\u3057\u3087\u3046\u304b\u3002\u305d\u306e\u5834\u5408\u3001\u3069\u308c\u304f\u3089\u3044\u306e\u983b\u5ea6\u3067\u305d\u306e\u3088\u3046\u306a\u30b7\u30b0\u30ca\u30eb\u3092\u53d7\u4fe1\u3059\u308b\u306e\u3067\u3057\u3087\u3046\u304b\u3002\u3042\u308b\u3044\u306f\u518d\u63a5\u7d9a\u3057\u305f\u3068\u3044\u3046\u3053\u3068\u3067\u3057\u3087\u3046\u304b\u3002\u305d\u3082\u305d\u3082 false
\u3092\u53d7\u3051\u53d6\u308b\u3053\u3068\u3092\u671f\u5f85\u3059\u3079\u304d\u306a\u306e\u3067\u3057\u3087\u3046\u304b\u3002\u304a\u305d\u3089\u304f true
\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u53d7\u3051\u53d6\u308b\u3053\u3068\u3060\u3051\u3092\u671f\u5f85\u3059\u3079\u304d\u3067\u3057\u3087\u3046\u3002
\u305d\u306e\u5834\u5408\u3001\u60c5\u5831\u3092\u4f1d\u3048\u308b\u305f\u3081\u306b\u7279\u5b9a\u306e\u5024\u306f\u5fc5\u8981\u306a\u3044\u3053\u3068\u3092\u610f\u5473\u3057\u3001\u30c7\u30fc\u30bf\u306e \u306a\u3044 \u30c1\u30e3\u30cd\u30eb\u304c\u5fc5\u8981\u306b\u306a\u308a\u307e\u3059\u3002\u3053\u308c\u3092\u51e6\u7406\u3059\u308b\u6163\u7528\u7684\u306a\u65b9\u6cd5\u306f\u3001\u7a7a\u306e\u69cb\u9020\u4f53\u306e\u30c1\u30e3\u30cd\u30eb\u2015\u2015 chan struct{}
\u2015\u2015\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u3067\u3059\u3002
nil \u30c1\u30e3\u30cd\u30eb\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u306b\u3088\u3063\u3066\u3001\u305f\u3068\u3048\u3070 select
\u6587\u304b\u3089\u30b1\u30fc\u30b9\u3092 \u524a\u9664 \u3067\u304d\u308b\u305f\u3081\u3001\u4e26\u884c\u51e6\u7406\u3092\u884c\u3046\u969b\u306e\u9053\u5177\u306e\u4e00\u3064\u3068\u3057\u3066\u4f7f\u3048\u308b\u3088\u3046\u306b\u306a\u308b\u3079\u304d\u3067\u3059\u3002
\u6b21\u306e\u30b3\u30fc\u30c9\u306b\u3088\u3063\u3066\u4f55\u304c\u884c\u308f\u308c\u308b\u3067\u3057\u3087\u3046\u304b\u3002
var ch chan int\n<-ch\n
ch
\u306f chan int
\u578b\u3067\u3059\u3002\u30c1\u30e3\u30cd\u30eb\u306e\u30bc\u30ed\u5024\u306f nil \u3067\u3042\u308b\u306e\u3067\u3001 ch
\u306f nil
\u3067\u3059\u3002\u30b4\u30eb\u30fc\u30c1\u30f3\u306f panic \u3092\u8d77\u3053\u3057\u307e\u305b\u3093\u3002\u305f\u3060\u3057\u3001\u6c38\u4e45\u306b\u30d6\u30ed\u30c3\u30af\u3057\u307e\u3059\u3002
nil \u30c1\u30e3\u30cd\u30eb\u306b\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u9001\u4fe1\u3059\u308b\u5834\u5408\u3082\u539f\u7406\u306f\u540c\u3058\u3067\u3059\u3002\u4ee5\u4e0b\u306e\u30b4\u30eb\u30fc\u30c1\u30f3\u306f\u6c38\u4e45\u306b\u30d6\u30ed\u30c3\u30af\u3057\u307e\u3059\u3002
var ch chan int\nch <- 0\n
\u3067\u306f\u3001Go\u8a00\u8a9e\u304c nil \u30c1\u30e3\u30cd\u30eb\u3068\u306e\u9593\u3067\u30e1\u30c3\u30bb\u30fc\u30b8\u306e\u9001\u53d7\u4fe1\u3092\u8a31\u53ef\u3059\u308b\u76ee\u7684\u306f\u4f55\u3067\u3057\u3087\u3046\u304b\u3002\u305f\u3068\u3048\u3070\u30012 \u3064\u306e\u30c1\u30e3\u30cd\u30eb\u3092\u30de\u30fc\u30b8\u3059\u308b\u6163\u7528\u7684\u306a\u65b9\u6cd5\u3092\u5b9f\u88c5\u3059\u308b\u306e\u306b\u3001 nil \u30c1\u30e3\u30cd\u30eb\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002
func merge(ch1, ch2 <-chan int) <-chan int {\n ch := make(chan int, 1)\n\n go func() {\n for ch1 != nil || ch2 != nil { // \u6700\u4f4e\u3067\u3082\u4e00\u3064\u306e\u30c1\u30e3\u30cd\u30eb\u304c nil \u3067\u306a\u3051\u308c\u3070\u7d9a\u884c\u3059\u308b\n select {\n case v, open := <-ch1:\n if !open {\n ch1 = nil // \u9589\u3058\u305f\u3089 ch1 \u3092 nil \u30c1\u30e3\u30cd\u30eb\u306b\u5272\u308a\u5f53\u3066\u308b\n break\n }\n ch <- v\n case v, open := <-ch2:\n if !open {\n ch2 = nil // \u9589\u3058\u305f\u3089 ch2 \u3092 nil \u30c1\u30e3\u30cd\u30eb\u306b\u5272\u308a\u5f53\u3066\u308b\n break\n }\n ch <- v\n }\n }\n close(ch)\n }()\n\n return ch\n}\n
\u3053\u306e\u6d17\u7df4\u3055\u308c\u305f\u89e3\u6c7a\u7b56\u306f\u3001nil \u30c1\u30e3\u30cd\u30eb\u3092\u5229\u7528\u3057\u3066\u3001\u4f55\u3089\u304b\u306e\u65b9\u6cd5\u3067 select
\u6587\u304b\u3089 1 \u3064\u306e\u30b1\u30fc\u30b9\u3092 \u524a\u9664 \u3057\u307e\u3059\u3002
nil \u30c1\u30e3\u30cd\u30eb\u306f\u72b6\u6cc1\u306b\u3088\u3063\u3066\u306f\u4fbf\u5229\u3067\u3042\u308a\u3001Go \u958b\u767a\u8005\u306f\u4e26\u884c\u51e6\u7406\u3092\u6271\u3046\u969b\u306b\u4f7f\u3044\u3053\u306a\u305b\u308b\u3088\u3046\u306b\u306a\u3063\u3066\u304a\u304f\u3079\u304d\u3067\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#67","title":"\u30c1\u30e3\u30cd\u30eb\u306e\u5bb9\u91cf\u306b\u3064\u3044\u3066\u56f0\u60d1\u3057\u3066\u3044\u308b (#67)","text":"\u8981\u7d04\u554f\u984c\u304c\u767a\u751f\u3057\u305f\u5834\u5408\u306f\u3001\u4f7f\u7528\u3059\u308b\u30c1\u30e3\u30cd\u30eb\u306e\u578b\u3092\u614e\u91cd\u306b\u6c7a\u5b9a\u3057\u3066\u304f\u3060\u3055\u3044\u3002\u540c\u671f\u3092\u5f37\u529b\u306b\u4fdd\u8a3c\u3057\u3066\u304f\u308c\u308b\u306e\u306f\u30d0\u30c3\u30d5\u30a1\u306a\u3057\u30c1\u30e3\u30cd\u30eb\u306e\u307f\u3067\u3059\u3002
\u30d0\u30c3\u30d5\u30a1\u3042\u308a\u30c1\u30e3\u30cd\u30eb\u4ee5\u5916\u306e\u30c1\u30e3\u30cd\u30eb\u306e\u5bb9\u91cf\u3092\u6307\u5b9a\u3059\u308b\u306b\u306f\u6b63\u5f53\u306a\u7406\u7531\u304c\u3042\u308b\u3079\u304d\u3067\u3059\u3002
"},{"location":"ja/#etcd-68","title":"\u6587\u5b57\u5217\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u3067\u8d77\u3053\u308a\u5f97\u308b\u526f\u4f5c\u7528\u3092\u5fd8\u308c\u3066\u3057\u307e\u3046\uff08 etcd \u30c7\u30fc\u30bf\u7af6\u5408\u306e\u4f8b\u3068\u30c7\u30c3\u30c9\u30ed\u30c3\u30af\uff09 (#68)","text":"\u8981\u7d04\u6587\u5b57\u5217\u306e\u66f8\u5f0f\u8a2d\u5b9a\u304c\u65e2\u5b58\u306e\u95a2\u6570\u304c\u547c\u3073\u51fa\u3059\u53ef\u80fd\u6027\u304c\u3042\u308b\u3053\u3068\u3092\u8a8d\u8b58\u3059\u308b\u3053\u3068\u306f\u3001\u30c7\u30c3\u30c9\u30ed\u30c3\u30af\u3084\u305d\u306e\u4ed6\u306e\u30c7\u30fc\u30bf\u7af6\u5408\u306e\u53ef\u80fd\u6027\u306b\u6ce8\u610f\u3059\u308b\u3053\u3068\u3092\u610f\u5473\u3057\u307e\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#append-69","title":"append
\u3067\u30c7\u30fc\u30bf\u7af6\u5408\u3092\u8d77\u3053\u3057\u3066\u3057\u307e\u3046 (#69)","text":"\u8981\u7d04 append
\u306e\u547c\u3073\u51fa\u3057\u306f\u5fc5\u305a\u3057\u3082\u30c7\u30fc\u30bf\u7af6\u5408\u304c\u306a\u3044\u308f\u3051\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u3002\u3086\u3048\u306b\u3001\u5171\u6709\u30b9\u30e9\u30a4\u30b9\u4e0a\u3067\u540c\u6642\u306b\u4f7f\u7528\u3057\u3066\u306f\u3044\u3051\u307e\u305b\u3093\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#70","title":"\u30b9\u30e9\u30a4\u30b9\u3068\u30de\u30c3\u30d7\u3067\u30df\u30e5\u30fc\u30c6\u30c3\u30af\u30b9\u3092\u6b63\u3057\u304f\u4f7f\u7528\u3057\u3066\u3044\u306a\u3044 (#70)","text":"\u8981\u7d04\u30b9\u30e9\u30a4\u30b9\u3068\u30de\u30c3\u30d7\u306f\u30dd\u30a4\u30f3\u30bf\u3067\u3042\u308b\u3053\u3068\u3092\u899a\u3048\u3066\u304a\u304f\u3068\u3001\u5178\u578b\u7684\u306a\u30c7\u30fc\u30bf\u7af6\u5408\u3092\u9632\u3050\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#syncwaitgroup-71","title":"sync.WaitGroup
\u3092\u6b63\u3057\u304f\u4f7f\u7528\u3057\u3066\u3044\u306a\u3044 (#71)","text":"\u8981\u7d04 sync.WaitGroup
\u3092\u6b63\u3057\u304f\u4f7f\u7528\u3059\u308b\u306b\u306f\u3001\u30b4\u30eb\u30fc\u30c1\u30f3\u3092\u8d77\u52d5\u3059\u308b\u524d\u306b Add
\u30e1\u30bd\u30c3\u30c9\u3092\u547c\u3073\u51fa\u3057\u307e\u3057\u3087\u3046\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#synccond-72","title":"sync.Cond
\u306b\u3064\u3044\u3066\u5fd8\u308c\u3066\u3057\u307e\u3046 (#72)","text":"\u8981\u7d04 sync.Cond
\u3092\u4f7f\u7528\u3059\u308b\u3068\u3001\u8907\u6570\u306e\u30b4\u30eb\u30fc\u30c1\u30f3\u306b\u7e70\u308a\u8fd4\u3057\u901a\u77e5\u3092\u9001\u4fe1\u3067\u304d\u307e\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#errgroup-73","title":"errgroup
\u3092\u4f7f\u7528\u3057\u3066\u3044\u306a\u3044 (#73)","text":"\u8981\u7d04 errgroup
\u30d1\u30c3\u30b1\u30fc\u30b8\u3092\u4f7f\u7528\u3057\u3066\u3001\u30b4\u30eb\u30fc\u30c1\u30f3\u306e\u30b0\u30eb\u30fc\u30d7\u3092\u540c\u671f\u3057\u3001\u30a8\u30e9\u30fc\u3068 Context \u3092\u51e6\u7406\u3067\u304d\u307e\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#sync-74","title":"sync
\u578b\u306e\u30b3\u30d4\u30fc (#74)","text":"\u8981\u7d04 sync
\u578b\u306f\u30b3\u30d4\u30fc\u3055\u308c\u308b\u3079\u304d\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#_15","title":"\u6a19\u6e96\u30e9\u30a4\u30d6\u30e9\u30ea","text":""},{"location":"ja/#75","title":"\u9593\u9055\u3063\u305f\u6642\u9593\u3092\u6307\u5b9a\u3059\u308b (#75)","text":"\u8981\u7d04time.Duration
\u3092\u53d7\u3051\u5165\u308c\u308b\u95a2\u6570\u306b\u306f\u6ce8\u610f\u3092\u6255\u3063\u3066\u304f\u3060\u3055\u3044\u3002\u6574\u6570\u3092\u6e21\u3059\u3053\u3068\u306f\u8a31\u53ef\u3055\u308c\u3066\u3044\u307e\u3059\u304c\u3001\u6df7\u4e71\u3092\u62db\u304b\u306a\u3044\u3088\u3046\u306b time API \u3092\u4f7f\u7528\u3059\u308b\u3088\u3046\u52aa\u3081\u3066\u304f\u3060\u3055\u3044\u3002
\u6a19\u6e96\u30e9\u30a4\u30d6\u30e9\u30ea\u306e\u591a\u304f\u306e\u95a2\u6570\u306f\u3001int64
\u578b\u306e\u30a8\u30a4\u30ea\u30a2\u30b9\u3067\u3042\u308b time.Duration
\u3092\u53d7\u3051\u5165\u308c\u307e\u3059\u3002\u305f\u3060\u3057\u30011 \u5358\u4f4d\u306e time.Duration
\u306f\u3001\u4ed6\u306e\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u8a00\u8a9e\u3067\u4e00\u822c\u7684\u306b\u898b\u3089\u308c\u308b 1 \u30df\u30ea\u79d2\u3067\u306f\u306a\u304f\u30011 \u30ca\u30ce\u79d2\u3092\u8868\u3057\u307e\u3059\u3002\u305d\u306e\u7d50\u679c\u3001time.Duration
API \u3092\u4f7f\u7528\u3059\u308b\u4ee3\u308f\u308a\u306b\u6570\u5024\u578b\u3092\u6e21\u3059\u3068\u3001\u4e88\u60f3\u5916\u306e\u52d5\u4f5c\u304c\u767a\u751f\u3059\u308b\u53ef\u80fd\u6027\u304c\u3042\u308a\u307e\u3059\u3002
\u4ed6\u8a00\u8a9e\u3092\u4f7f\u7528\u3057\u305f\u3053\u3068\u306e\u3042\u308b\u958b\u767a\u8005\u306e\u65b9\u306f\u3001\u6b21\u306e\u30b3\u30fc\u30c9\u306b\u3088\u3063\u3066 1 \u79d2\u5468\u671f\u306e\u65b0\u3057\u3044 time.Ticker
\u304c\u751f\u6210\u3055\u308c\u308b\u3068\u8003\u3048\u308b\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002
ticker := time.NewTicker(1000)\nfor {\n select {\n case <-ticker.C:\n // \u51e6\u7406\u3092\u3059\u308b\n }\n}\n
\u3057\u304b\u3057\u306a\u304c\u3089\u30011,000 time.Duration
= 1,000 \u30ca\u30ce\u79d2\u3067\u3042\u308b\u305f\u3081\u3001\u60f3\u5b9a\u3055\u308c\u3066\u3044\u308b 1\u79d2 \u3067\u306f\u306a\u304f\u30011,000 \u30ca\u30ce\u79d2 = 1 \u30de\u30a4\u30af\u30ed\u79d2\u306e\u5468\u671f\u306b\u306a\u308a\u307e\u3059\u3002
\u6df7\u4e71\u3084\u4e88\u60f3\u5916\u306e\u52d5\u4f5c\u3092\u62db\u304b\u306a\u3044\u3088\u3046\u3001\u3044\u3064\u3082 time.Duration
API \u3092\u4f7f\u7528\u3059\u308b\u3079\u304d\u3067\u3059\u3002
ticker = time.NewTicker(time.Microsecond)\n// \u3082\u3057\u304f\u306f\nticker = time.NewTicker(1000 * time.Nanosecond)\n
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#timeafter-76","title":"time.After
\u3068\u30e1\u30e2\u30ea\u30ea\u30fc\u30af (#76)","text":"\u8981\u7d04 \u7e70\u308a\u8fd4\u3055\u308c\u308b\u95a2\u6570\uff08\u30eb\u30fc\u30d7\u3084 HTTP \u30cf\u30f3\u30c9\u30e9\u306a\u3069\uff09\u3067 time.After
\u306e\u547c\u3073\u51fa\u3057\u3092\u56de\u907f\u3059\u308b\u3068\u3001\u30d4\u30fc\u30af\u6642\u306e\u30e1\u30e2\u30ea\u6d88\u8cbb\u3092\u56de\u907f\u3067\u304d\u307e\u3059\u3002time.After
\u306b\u3088\u3063\u3066\u751f\u6210\u3055\u308c\u305f\u30ea\u30bd\u30fc\u30b9\u306f\u3001 timer \u304c\u7d42\u4e86\u3057\u305f\u3068\u304d\u306b\u306e\u307f\u89e3\u653e\u3055\u308c\u307e\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#json-77","title":"JSON \u51e6\u7406\u3067\u3042\u308a\u304c\u3061\u306a\u9593\u9055\u3044 (#77)","text":"Go \u69cb\u9020\u4f53\u3067\u57cb\u3081\u8fbc\u307f\u30d5\u30a3\u30fc\u30eb\u30c9\u3092\u4f7f\u7528\u3059\u308b\u5834\u5408\u306f\u6ce8\u610f\u3057\u3066\u304f\u3060\u3055\u3044\u3002 \u306a\u305c\u306a\u3089 json.Marshaler
\u30a4\u30f3\u30bf\u30d5\u30a7\u30fc\u30b9\u3092\u5b9f\u88c5\u3059\u308b time.Time \u57cb\u3081\u8fbc\u307f\u30d5\u30a3\u30fc\u30eb\u30c9\u306e\u3088\u3046\u306a\u3084\u3063\u304b\u3044\u306a\u30d0\u30b0\u304c\u767a\u751f\u3057\u3066\u3001\u30c7\u30d5\u30a9\u30eb\u30c8\u306e\u30de\u30fc\u30b7\u30e3\u30ea\u30f3\u30b0\u52d5\u4f5c\u304c\u30aa\u30fc\u30d0\u30fc\u30e9\u30a4\u30c9\u3055\u308c\u308b\u53ef\u80fd\u6027\u304c\u3042\u308b\u304b\u3089\u3067\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
2 \u3064\u306e time.Time
\u69cb\u9020\u4f53\u3092\u6bd4\u8f03\u3059\u308b\u5834\u5408\u3001time.Time
\u306b\u306f wall clock \u3068 monotonic clock \u306e\u4e21\u65b9\u304c\u542b\u307e\u308c\u3066\u304a\u308a\u3001== \u6f14\u7b97\u5b50\u3092\u4f7f\u7528\u3057\u305f\u6bd4\u8f03\u306f\u4e21\u65b9\u306e clock \u306b\u5bfe\u3057\u3066\u884c\u308f\u308c\u308b\u3053\u3068\u3092\u601d\u3044\u51fa\u3057\u3066\u304f\u3060\u3055\u3044\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
any
\u306e\u30de\u30c3\u30d7JSON \u30c7\u30fc\u30bf\u306e\u30a2\u30f3\u30de\u30fc\u30b7\u30e3\u30ea\u30f3\u30b0\u4e2d\u306b\u30de\u30c3\u30d7\u3092\u63d0\u4f9b\u3059\u308b\u3068\u304d\u306b\u9593\u9055\u3044\u3092\u907f\u3051\u308b\u305f\u3081\u306b\u3001\u6570\u5024\u306f\u30c7\u30d5\u30a9\u30eb\u30c8\u3067 float64
\u306b\u5909\u63db\u3055\u308c\u308b\u3053\u3068\u306b\u6ce8\u610f\u3057\u3066\u304f\u3060\u3055\u3044\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#sql-78","title":"SQL \u3067\u3042\u308a\u304c\u3061\u306a\u9593\u9055\u3044 (#78)","text":"sql.Open
\u304c\u5fc5\u305a\u3057\u3082\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3078\u306e\u63a5\u7d9a\u3092\u78ba\u7acb\u3059\u308b\u308f\u3051\u3067\u306f\u306a\u3044\u3053\u3068\u3092\u5fd8\u308c\u3066\u3044\u308b\u8a2d\u5b9a\u3092\u8a66\u3057\u3001\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306b\u30a2\u30af\u30bb\u30b9\u3067\u304d\u308b\u3053\u3068\u3092\u78ba\u8a8d\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u5834\u5408\u306f\u3001 Ping
\u307e\u305f\u306f PingContext
\u30e1\u30bd\u30c3\u30c9\u3092\u547c\u3073\u51fa\u3057\u307e\u3057\u3087\u3046\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
\u5b9f\u904b\u7528\u6c34\u6e96\u306e\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3067\u306f\u3001\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u63a5\u7d9a\u30d1\u30e9\u30e1\u30fc\u30bf\u3092\u8a2d\u5b9a\u3057\u307e\u3057\u3087\u3046\u3002
SQL \u306e\u30d7\u30ea\u30da\u30a2\u30c9\u30b9\u30c6\u30fc\u30c8\u30e1\u30f3\u30c8\u3092\u4f7f\u7528\u3059\u308b\u3068\u3001\u30af\u30a8\u30ea\u304c\u3088\u308a\u52b9\u7387\u7684\u304b\u3064\u78ba\u5b9f\u306b\u306a\u308a\u307e\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
\u30c6\u30fc\u30d6\u30eb\u5185\u306e null \u304c\u8a31\u5bb9\u3055\u308c\u3066\u3044\u308b\u5217\u306f\u3001\u30dd\u30a4\u30f3\u30bf\u307e\u305f\u306f sql.NullXXX
\u578b\u3092\u4f7f\u7528\u3057\u3066\u51e6\u7406\u3057\u307e\u3057\u3087\u3046\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
\u884c\u306e\u53cd\u5fa9\u51e6\u7406\u306e\u5f8c\u306b sql.Rows
\u306e Err
\u30e1\u30bd\u30c3\u30c9\u3092\u547c\u3073\u51fa\u3057\u3066\u3001\u6b21\u306e\u884c\u306e\u6e96\u5099\u4e2d\u306b\u30a8\u30e9\u30fc\u3092\u898b\u9003\u3057\u3066\u3044\u306a\u3044\u3053\u3068\u3092\u78ba\u8a8d\u3057\u307e\u3057\u3087\u3046\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#http-bodysqlrows-osfile-79","title":"\u4e00\u6642\u7684\u306a\u30ea\u30bd\u30fc\u30b9\uff08 HTTP body\u3001sql.Rows
\u3001\u304a\u3088\u3073 os.File
\uff09\u3092\u9589\u3058\u3066\u3044\u306a\u3044 (#79)","text":"\u8981\u7d04 \u30ea\u30fc\u30af\u3092\u907f\u3051\u308b\u305f\u3081\u306b\u3001 io.Closer
\u3092\u5b9f\u88c5\u3057\u3066\u3044\u308b\u3059\u3079\u3066\u306e\u69cb\u9020\u4f53\u3092\u6700\u5f8c\u306b\u306f\u9589\u3058\u307e\u3057\u3087\u3046\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#http-return-80","title":"HTTP \u30ea\u30af\u30a8\u30b9\u30c8\u306b\u5fdc\u7b54\u3057\u305f\u5f8c\u306e return \u6587\u3092\u5fd8\u308c\u3066\u3057\u307e\u3046 (#80)","text":"\u8981\u7d04HTTP \u30cf\u30f3\u30c9\u30e9\u306e\u5b9f\u88c5\u3067\u306e\u4e88\u60f3\u5916\u306e\u52d5\u4f5c\u3092\u907f\u3051\u308b\u305f\u3081\u3001http.Error
\u306e\u5f8c\u306b\u30cf\u30f3\u30c9\u30e9\u3092\u505c\u6b62\u3057\u305f\u3044\u5834\u5408\u306f\u3001return
\u6587\u3092\u5fd8\u308c\u306a\u3044\u3088\u3046\u306b\u3057\u3066\u304f\u3060\u3055\u3044\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#http-81","title":"\u6a19\u6e96\u306e HTTP \u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u3068\u30b5\u30fc\u30d0\u30fc\u3092\u4f7f\u7528\u3057\u3066\u3044\u308b (#81)","text":"\u8981\u7d04\u5b9f\u904b\u7528\u6c34\u6e96\u306e\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u6c42\u3081\u3066\u3044\u308b\u5834\u5408\u306f\u3001\u6a19\u6e96\u306e HTTP \u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u3068\u30b5\u30fc\u30d0\u30fc\u306e\u5b9f\u88c5\u3092\u4f7f\u7528\u3057\u306a\u3044\u3067\u304f\u3060\u3055\u3044\u3002\u3053\u308c\u3089\u306e\u5b9f\u88c5\u306b\u306f\u3001\u30bf\u30a4\u30e0\u30a2\u30a6\u30c8\u3084\u7a3c\u50cd\u74b0\u5883\u3067\u5fc5\u9808\u3067\u3042\u308b\u3079\u304d\u52d5\u4f5c\u304c\u6b20\u843d\u3057\u3066\u3044\u307e\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#_16","title":"\u30c6\u30b9\u30c8","text":""},{"location":"ja/#82","title":"\u30c6\u30b9\u30c8\u3092\u5206\u985e\u3057\u3066\u3044\u306a\u3044\uff08\u30d3\u30eb\u30c9\u30bf\u30b0\u3001\u74b0\u5883\u5909\u6570\u3001\u30b7\u30e7\u30fc\u30c8\u30e2\u30fc\u30c9\uff09 (#82)","text":"\u8981\u7d04\u30d3\u30eb\u30c9\u30d5\u30e9\u30b0\u3001\u74b0\u5883\u5909\u6570\u3001\u307e\u305f\u306f\u30b7\u30e7\u30fc\u30c8\u30e2\u30fc\u30c9\u3092\u4f7f\u7528\u3057\u3066\u30c6\u30b9\u30c8\u3092\u5206\u985e\u3059\u308b\u3068\u3001\u30c6\u30b9\u30c8\u30d7\u30ed\u30bb\u30b9\u304c\u3088\u308a\u52b9\u7387\u7684\u306b\u306a\u308a\u307e\u3059\u3002\u30d3\u30eb\u30c9\u30d5\u30e9\u30b0\u307e\u305f\u306f\u74b0\u5883\u5909\u6570\u3092\u4f7f\u7528\u3057\u3066\u30c6\u30b9\u30c8\u30ab\u30c6\u30b4\u30ea\uff08\u305f\u3068\u3048\u3070\u3001\u5358\u4f53\u30c6\u30b9\u30c8\u3068\u7d71\u5408\u30c6\u30b9\u30c8\uff09\u3092\u4f5c\u6210\u3057\u3001\u77ed\u671f\u9593\u306e\u30c6\u30b9\u30c8\u3068\u9577\u6642\u9593\u306e\u30c6\u30b9\u30c8\u3092\u533a\u5225\u3059\u308b\u3053\u3068\u3067\u3001\u5b9f\u884c\u3059\u308b\u30c6\u30b9\u30c8\u306e\u7a2e\u985e\u3092\u6c7a\u5b9a\u3067\u304d\u307e\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#-race-83","title":"-race
\u30d5\u30e9\u30b0\u3092\u6709\u52b9\u306b\u3057\u3066\u3044\u306a\u3044 (#83)","text":"\u8981\u7d04 \u4e26\u884c\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u4f5c\u6210\u3059\u308b\u5834\u5408\u306f\u3001 -race
\u30d5\u30e9\u30b0\u3092\u6709\u52b9\u306b\u3059\u308b\u3053\u3068\u3092\u5f37\u304f\u304a\u52e7\u3081\u3057\u307e\u3059\u3002\u305d\u3046\u3059\u308b\u3053\u3068\u3067\u3001\u30bd\u30d5\u30c8\u30a6\u30a7\u30a2\u306e\u30d0\u30b0\u306b\u3064\u306a\u304c\u308b\u53ef\u80fd\u6027\u306e\u3042\u308b\u6f5c\u5728\u7684\u306a\u30c7\u30fc\u30bf\u7af6\u5408\u3092\u767a\u898b\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002
-parallel
\u304a\u3088\u3073 -shuffle
\uff09\u3092\u4f7f\u7528\u3057\u3066\u3044\u306a\u3044 (#84)","text":"\u8981\u7d04 -parallel
\u30d5\u30e9\u30b0\u3092\u4f7f\u7528\u3059\u308b\u306e\u306f\u3001\u7279\u306b\u9577\u6642\u9593\u5b9f\u884c\u3055\u308c\u308b\u30c6\u30b9\u30c8\u3092\u9ad8\u901f\u5316\u3059\u308b\u306e\u306b\u52b9\u679c\u7684\u3067\u3059\u3002 -shuffle
\u30d5\u30e9\u30b0\u3092\u4f7f\u7528\u3059\u308b\u3068\u3001\u30c6\u30b9\u30c8\u30b9\u30a4\u30fc\u30c8\u304c\u30d0\u30b0\u3092\u96a0\u3059\u53ef\u80fd\u6027\u306e\u3042\u308b\u9593\u9055\u3063\u305f\u4eee\u5b9a\u306b\u4f9d\u5b58\u3057\u306a\u3044\u3088\u3046\u306b\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002
\u30c6\u30fc\u30d6\u30eb\u99c6\u52d5\u30c6\u30b9\u30c8\u306f\u3001\u30b3\u30fc\u30c9\u306e\u91cd\u8907\u3092\u9632\u304e\u3001\u5c06\u6765\u306e\u66f4\u65b0\u306e\u51e6\u7406\u3092\u5bb9\u6613\u306b\u3059\u308b\u305f\u3081\u306b\u3001\u4e00\u9023\u306e\u985e\u4f3c\u3057\u305f\u30c6\u30b9\u30c8\u3092\u30b0\u30eb\u30fc\u30d7\u5316\u3059\u308b\u52b9\u7387\u7684\u306a\u65b9\u6cd5\u3067\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#86","title":"\u5358\u4f53\u30c6\u30b9\u30c8\u3067\u306e\u30b9\u30ea\u30fc\u30d7 (#86)","text":"\u8981\u7d04\u30c6\u30b9\u30c8\u306e\u4e0d\u5b89\u5b9a\u3055\u3092\u306a\u304f\u3057\u3001\u3088\u308a\u5805\u7262\u306b\u3059\u308b\u305f\u3081\u306b\u3001\u540c\u671f\u3092\u4f7f\u7528\u3057\u3066\u30b9\u30ea\u30fc\u30d7\u3092\u56de\u907f\u3057\u307e\u3057\u3087\u3046\u3002\u540c\u671f\u304c\u4e0d\u53ef\u80fd\u306a\u5834\u5408\u306f\u3001\u30ea\u30c8\u30e9\u30a4\u624b\u6cd5\u3092\u691c\u8a0e\u3057\u3066\u304f\u3060\u3055\u3044\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#time-api-87","title":"time API \u3092\u52b9\u7387\u7684\u306b\u51e6\u7406\u3067\u304d\u3066\u3044\u306a\u3044 (#87)","text":"\u8981\u7d04time API \u3092\u4f7f\u7528\u3057\u3066\u95a2\u6570\u3092\u51e6\u7406\u3059\u308b\u65b9\u6cd5\u3092\u7406\u89e3\u3059\u308b\u3053\u3068\u3067\u3001\u30c6\u30b9\u30c8\u306e\u4e0d\u5b89\u5b9a\u3055\u3092\u8efd\u6e1b\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u96a0\u308c\u305f\u4f9d\u5b58\u95a2\u4fc2\u306e\u4e00\u90e8\u3068\u3057\u3066 time \u3092\u51e6\u7406\u3057\u305f\u308a\u3001\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u306b time \u3092\u63d0\u4f9b\u3059\u308b\u3088\u3046\u306b\u8981\u6c42\u3057\u305f\u308a\u3059\u308b\u306a\u3069\u3001\u6a19\u6e96\u7684\u306a\u624b\u6bb5\u3092\u5229\u7528\u3067\u304d\u307e\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#httptest-iotest-88","title":"\u30c6\u30b9\u30c8\u306b\u95a2\u3059\u308b\u30e6\u30fc\u30c6\u30a3\u30ea\u30c6\u30a3\u30d1\u30c3\u30b1\u30fc\u30b8\uff08httptest
\u304a\u3088\u3073 iotest
\uff09\u3092\u4f7f\u7528\u3057\u3066\u3044\u306a\u3044 (#88)","text":"httptest
\u30d1\u30c3\u30b1\u30fc\u30b8\u306f\u3001HTTP \u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u6271\u3046\u306e\u306b\u5f79\u7acb\u3061\u307e\u3059\u3002\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u3068\u30b5\u30fc\u30d0\u30fc\u306e\u4e21\u65b9\u3092\u30c6\u30b9\u30c8\u3059\u308b\u305f\u3081\u306e\u4e00\u9023\u306e\u30e6\u30fc\u30c6\u30a3\u30ea\u30c6\u30a3\u3092\u63d0\u4f9b\u3057\u307e\u3059\u3002\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
iotest
\u30d1\u30c3\u30b1\u30fc\u30b8\u306f\u3001io.Reader \u3092\u4f5c\u6210\u3057\u3001\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u30a8\u30e9\u30fc\u8010\u6027\u3092\u30c6\u30b9\u30c8\u3059\u308b\u306e\u306b\u5f79\u7acb\u3061\u307e\u3059\u3002\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#89","title":"\u4e0d\u6b63\u78ba\u306a\u30d9\u30f3\u30c1\u30de\u30fc\u30af\u306e\u4f5c\u6210 (#89)","text":"\u8981\u7d04\u30d9\u30f3\u30c1\u30de\u30fc\u30af\u306b\u3064\u3044\u3066
\u30bb\u30af\u30b7\u30e7\u30f3\u5168\u6587\u306f\u3053\u3061\u3089\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#go-90","title":"Go\u8a00\u8a9e\u306e\u30c6\u30b9\u30c8\u6a5f\u80fd\u3092\u3059\u3079\u3066\u8a66\u3057\u3066\u3044\u306a\u3044 (#90)","text":"\u30b3\u30fc\u30c9\u306e\u3069\u306e\u90e8\u5206\u306b\u6ce8\u610f\u304c\u5fc5\u8981\u304b\u3092\u3059\u3050\u306b\u78ba\u8a8d\u3059\u308b\u305f\u3081\u306b\u3001-coverprofile
\u30d5\u30e9\u30b0\u3092\u6307\u5b9a\u3057\u3066\u30b3\u30fc\u30c9\u30ab\u30d0\u30ec\u30c3\u30b8\u3092\u4f7f\u7528\u3057\u307e\u3057\u3087\u3046\u3002
\u5185\u90e8\u3067\u306f\u306a\u304f\u516c\u958b\u3055\u308c\u305f\u52d5\u4f5c\u306b\u7126\u70b9\u3092\u5f53\u3066\u305f\u30c6\u30b9\u30c8\u306e\u4f5c\u6210\u3092\u5f37\u5236\u3059\u308b\u305f\u3081\u306b\u3001\u5358\u4f53\u30c6\u30b9\u30c8\u306f\u5225\u3005\u306e\u30d1\u30c3\u30b1\u30fc\u30b8\u306b\u914d\u7f6e\u3057\u307e\u3057\u3087\u3046\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
\u5f93\u6765\u306e if err != nil
\u306e\u4ee3\u308f\u308a\u306b *testing.T
\u5909\u6570\u3092\u4f7f\u7528\u3057\u3066\u30a8\u30e9\u30fc\u3092\u51e6\u7406\u3059\u308b\u3068\u3001\u30b3\u30fc\u30c9\u304c\u77ed\u304f\u3001\u8aad\u307f\u3084\u3059\u304f\u306a\u308a\u307e\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
setup \u304a\u3088\u3073 teardown \u6a5f\u80fd\u3092\u5229\u7528\u3057\u3066\u3001\u7d71\u5408\u30c6\u30b9\u30c8\u306e\u5834\u5408\u306a\u3069\u3001\u8907\u96d1\u306a\u74b0\u5883\u3092\u69cb\u6210\u3067\u304d\u307e\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#community-mistake","title":"\u30d5\u30a1\u30b8\u30f3\u30b0\u3092\u4f7f\u7528\u3057\u3066\u3044\u306a\u3044\uff08community mistake\uff09","text":"\u8981\u7d04\u30d5\u30a1\u30b8\u30f3\u30b0\u306f\u3001\u8907\u96d1\u306a\u95a2\u6570\u3084\u30e1\u30bd\u30c3\u30c9\u3078\u306e\u30e9\u30f3\u30c0\u30e0\u306a\u3001\u4e88\u60f3\u5916\u306e\u3001\u307e\u305f\u306f\u4e0d\u6b63\u306a\u5165\u529b\u3092\u691c\u51fa\u3057\u3001\u8106\u5f31\u6027\u3001\u30d0\u30b0\u3001\u3055\u3089\u306b\u306f\u6f5c\u5728\u7684\u306a\u30af\u30e9\u30c3\u30b7\u30e5\u3092\u767a\u898b\u3059\u308b\u306e\u306b\u52b9\u7387\u7684\u3067\u3059\u3002
@jeromedoucet \u3055\u3093\u306e\u3054\u5354\u529b\u306b\u611f\u8b1d\u3044\u305f\u3057\u307e\u3059\u3002
"},{"location":"ja/#_17","title":"\u6700\u9069\u5316","text":""},{"location":"ja/#cpu-91","title":"CPU \u30ad\u30e3\u30c3\u30b7\u30e5\u3092\u7406\u89e3\u3057\u3066\u3044\u306a\u3044 (#91)","text":"L1 \u30ad\u30e3\u30c3\u30b7\u30e5\u306f\u30e1\u30a4\u30f3\u30e1\u30e2\u30ea\u3088\u308a\u3082\u7d04 50 \uff5e 100 \u500d\u9ad8\u901f\u3067\u3042\u308b\u305f\u3081\u3001CPU \u30d0\u30a6\u30f3\u30c9\u306e\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u6700\u9069\u5316\u3059\u308b\u306b\u306f\u3001CPU \u30ad\u30e3\u30c3\u30b7\u30e5\u306e\u4f7f\u7528\u65b9\u6cd5\u3092\u7406\u89e3\u3059\u308b\u3053\u3068\u304c\u91cd\u8981\u3067\u3059\u3002
\u30ad\u30e3\u30c3\u30b7\u30e5\u30e9\u30a4\u30f3\u306e\u6982\u5ff5\u3092\u610f\u8b58\u3059\u308b\u3053\u3068\u306f\u3001\u30c7\u30fc\u30bf\u96c6\u7d04\u578b\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3067\u30c7\u30fc\u30bf\u3092\u6574\u7406\u3059\u308b\u65b9\u6cd5\u3092\u7406\u89e3\u3059\u308b\u306e\u306b\u91cd\u8981\u3067\u3059\u3002CPU \u306f\u30e1\u30e2\u30ea\u3092\u30ef\u30fc\u30c9\u3054\u3068\u306b\u30d5\u30a7\u30c3\u30c1\u3057\u307e\u305b\u3093\u3002\u4ee3\u308f\u308a\u306b\u3001\u901a\u5e38\u306f\u30e1\u30e2\u30ea\u30d6\u30ed\u30c3\u30af\u3092 64 \u30d0\u30a4\u30c8\u306e\u30ad\u30e3\u30c3\u30b7\u30e5\u30e9\u30a4\u30f3\u306b\u30b3\u30d4\u30fc\u3057\u307e\u3059\u3002\u500b\u3005\u306e\u30ad\u30e3\u30c3\u30b7\u30e5\u30e9\u30a4\u30f3\u3092\u6700\u5927\u9650\u306b\u6d3b\u7528\u3059\u308b\u306b\u306f\u3001\u7a7a\u9593\u7684\u5c40\u6240\u6027\u3092\u5f37\u5236\u3057\u3066\u304f\u3060\u3055\u3044\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
CPU \u306b\u3068\u3063\u3066\u4e88\u6e2c\u53ef\u80fd\u306a\u30b3\u30fc\u30c9\u306b\u3059\u308b\u3053\u3068\u306f\u3001\u7279\u5b9a\u306e\u95a2\u6570\u3092\u6700\u9069\u5316\u3059\u308b\u52b9\u7387\u7684\u306a\u65b9\u6cd5\u3067\u3082\u3042\u308a\u307e\u3059\u3002\u305f\u3068\u3048\u3070\u3001\u30e6\u30cb\u30c3\u30c8\u307e\u305f\u306f\u5b9a\u6570\u30b9\u30c8\u30e9\u30a4\u30c9\u306f CPU \u306b\u3068\u3063\u3066\u4e88\u6e2c\u53ef\u80fd\u3067\u3059\u304c\u3001\u975e\u30e6\u30cb\u30c3\u30c8\u30b9\u30c8\u30e9\u30a4\u30c9\uff08\u9023\u7d50\u30ea\u30b9\u30c8\u306a\u3069\uff09\u306f\u4e88\u6e2c\u3067\u304d\u307e\u305b\u3093\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
\u30ad\u30e3\u30c3\u30b7\u30e5\u304c\u30d1\u30fc\u30c6\u30a3\u30b7\u30e7\u30f3\u5316\u3055\u308c\u3066\u3044\u308b\u3053\u3068\u3092\u8a8d\u8b58\u3059\u308b\u3053\u3068\u3067\u3001\u91cd\u5927\u306a\u30b9\u30c8\u30e9\u30a4\u30c9\u3092\u56de\u907f\u3057\u3001\u30ad\u30e3\u30c3\u30b7\u30e5\u306e\u3054\u304f\u4e00\u90e8\u306e\u307f\u3092\u4f7f\u7528\u3059\u308b\u3088\u3046\u306b\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002
"},{"location":"ja/#92","title":"\u8aa4\u3063\u305f\u5171\u6709\u3092\u5f15\u304d\u8d77\u3053\u3059\u4e26\u884c\u51e6\u7406(#92)","text":"\u8981\u7d04\u4e0b\u4f4d\u30ec\u30d9\u30eb\u306e CPU \u30ad\u30e3\u30c3\u30b7\u30e5\u304c\u3059\u3079\u3066\u306e\u30b3\u30a2\u3067\u5171\u6709\u3055\u308c\u308b\u308f\u3051\u3067\u306f\u306a\u3044\u3053\u3068\u3092\u77e5\u3063\u3066\u304a\u304f\u3068\u3001\u4e26\u884c\u51e6\u7406\u306b\u304a\u3051\u308b\u306e\u8aa4\u3063\u305f\u5171\u6709\u306a\u3069\u3067\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u3092\u4f4e\u4e0b\u3055\u305b\u3066\u3057\u307e\u3046\u3053\u3068\u3092\u56de\u907f\u3067\u304d\u307e\u3059\u3002\u30e1\u30e2\u30ea\u306e\u5171\u6709\u306f\u3042\u308a\u3048\u306a\u3044\u306e\u3067\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#93","title":"\u547d\u4ee4\u30ec\u30d9\u30eb\u306e\u4e26\u5217\u6027\u3092\u8003\u616e\u3057\u306a\u3044 (#93)","text":"\u8981\u7d04\u547d\u4ee4\u30ec\u30d9\u30eb\u306e\u4e26\u5217\u6027\uff08ILP\uff09\u3092\u4f7f\u7528\u3057\u3066\u30b3\u30fc\u30c9\u306e\u7279\u5b9a\u306e\u90e8\u5206\u3092\u6700\u9069\u5316\u3057\u3001CPU \u304c\u3067\u304d\u308b\u3060\u3051\u591a\u304f\u306e\u547d\u4ee4\u3092\u4e26\u5217\u5b9f\u884c\u3067\u304d\u308b\u3088\u3046\u306b\u3057\u307e\u3057\u3087\u3046\u3002\u4e3b\u306a\u624b\u9806\u306e 1 \u3064\u306b\u30c7\u30fc\u30bf\u30cf\u30b6\u30fc\u30c9\u306e\u7279\u5b9a\u304c\u3042\u308a\u307e\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#94","title":"\u30c7\u30fc\u30bf\u306e\u914d\u7f6e\u3092\u610f\u8b58\u3057\u3066\u3044\u306a\u3044 (#94)","text":"\u8981\u7d04Go\u8a00\u8a9e\u3067\u306f\u3001\u57fa\u672c\u578b\u306f\u5404\u3005\u306e\u30b5\u30a4\u30ba\u306b\u5408\u308f\u305b\u3066\u914d\u7f6e\u3055\u308c\u308b\u3053\u3068\u3092\u899a\u3048\u3066\u304a\u304f\u3053\u3068\u3067\u3001\u3042\u308a\u304c\u3061\u306a\u9593\u9055\u3044\u3092\u907f\u3051\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u305f\u3068\u3048\u3070\u3001\u69cb\u9020\u4f53\u306e\u30d5\u30a3\u30fc\u30eb\u30c9\u3092\u30b5\u30a4\u30ba\u3067\u964d\u9806\u306b\u518d\u7de8\u6210\u3059\u308b\u3068\u3001\u69cb\u9020\u4f53\u304c\u3088\u308a\u30b3\u30f3\u30d1\u30af\u30c8\u306b\u306a\u308b\uff08\u30e1\u30e2\u30ea\u5272\u308a\u5f53\u3066\u304c\u5c11\u306a\u304f\u306a\u308a\u3001\u7a7a\u9593\u7684\u5c40\u6240\u6027\u304c\u5411\u4e0a\u3059\u308b\uff09\u53ef\u80fd\u6027\u304c\u3042\u308b\u3053\u3068\u306b\u7559\u610f\u3057\u3066\u304f\u3060\u3055\u3044\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#95","title":"\u30d2\u30fc\u30d7\u3068\u30b9\u30bf\u30c3\u30af\u306e\u9055\u3044\u3092\u7406\u89e3\u3057\u3066\u3044\u306a\u3044 (#95)","text":"\u8981\u7d04\u30d2\u30fc\u30d7\u3068\u30b9\u30bf\u30c3\u30af\u306e\u57fa\u672c\u7684\u306a\u9055\u3044\u3092\u7406\u89e3\u3059\u308b\u3053\u3068\u3082\u3001Go \u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u6700\u9069\u5316\u3059\u308b\u969b\u306b\u306f\u5927\u5207\u3067\u3059\u3002\u30b9\u30bf\u30c3\u30af\u5272\u308a\u5f53\u3066\u306f\u5bb9\u6613\u306a\u306e\u306b\u5bfe\u3057\u3066\u3001\u30d2\u30fc\u30d7\u5272\u308a\u5f53\u3066\u306f\u9045\u304f\u3001\u30e1\u30e2\u30ea\u306e\u30af\u30ea\u30fc\u30f3\u30a2\u30c3\u30d7\u306b GC \u3092\u5229\u7528\u3057\u307e\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#api-syncpool-96","title":"\u5272\u308a\u5f53\u3066\u3092\u6e1b\u3089\u3059\u65b9\u6cd5\u304c\u308f\u304b\u3063\u3066\u3044\u306a\u3044\uff08 API \u306e\u5909\u66f4\u3001\u30b3\u30f3\u30d1\u30a4\u30e9\u306e\u6700\u9069\u5316\u3001\u304a\u3088\u3073sync.Pool
\uff09 (#96)","text":"\u8981\u7d04 \u5272\u308a\u5f53\u3066\u3092\u6e1b\u3089\u3059\u3053\u3068\u3082\u3001Go \u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u6700\u9069\u5316\u3059\u308b\u4e0a\u3067\u91cd\u8981\u3067\u3059\u3002\u3053\u308c\u306f\u3001\u5171\u6709\u3092\u9632\u3050\u305f\u3081\u306b API \u3092\u614e\u91cd\u306b\u8a2d\u8a08\u3059\u308b\u3001\u4e00\u822c\u7684\u306a Go \u30b3\u30f3\u30d1\u30a4\u30e9\u306e\u6700\u9069\u5316\u3092\u7406\u89e3\u3059\u308b\u3001sync.Pool
\u3092\u4f7f\u7528\u3059\u308b\u306a\u3069\u3001\u3055\u307e\u3056\u307e\u306a\u65b9\u6cd5\u3067\u884c\u3046\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002
\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9
"},{"location":"ja/#97","title":"\u30a4\u30f3\u30e9\u30a4\u30f3\u5c55\u958b\u3092\u3057\u3066\u3044\u306a\u3044 (#97)","text":"\u8981\u7d04\u30d5\u30a1\u30b9\u30c8\u30d1\u30b9\u306e\u30a4\u30f3\u30e9\u30a4\u30f3\u5316\u624b\u6cd5\u3092\u4f7f\u7528\u3057\u3066\u3001\u95a2\u6570\u306e\u547c\u3073\u51fa\u3057\u306b\u304b\u304b\u308b\u511f\u5374\u6642\u9593\u3092\u52b9\u7387\u7684\u306b\u524a\u6e1b\u3057\u307e\u3057\u3087\u3046\u3002
"},{"location":"ja/#go-98","title":"Go\u8a00\u8a9e\u306e\u8a3a\u65ad\u30c4\u30fc\u30eb\u3092\u5229\u7528\u3057\u3066\u3044\u306a\u3044 (#98)","text":"\u8981\u7d04\u30d7\u30ed\u30d5\u30a1\u30a4\u30ea\u30f3\u30b0\u3068\u5b9f\u884c\u30c8\u30ec\u30fc\u30b5\u3092\u5229\u7528\u3057\u3066\u3001\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u3068\u6700\u9069\u5316\u3059\u3079\u304d\u90e8\u5206\u306b\u3064\u3044\u3066\u7406\u89e3\u3057\u307e\u3057\u3087\u3046\u3002
\u30bb\u30af\u30b7\u30e7\u30f3\u5168\u6587\u306f\u3053\u3061\u3089\u3002
"},{"location":"ja/#gc-99","title":"GC \u306e\u4ed5\u7d44\u307f\u3092\u7406\u89e3\u3057\u3066\u3044\u306a\u3044 (#99)","text":"\u8981\u7d04GC \u306e\u8abf\u6574\u65b9\u6cd5\u3092\u7406\u89e3\u3059\u308b\u3068\u3001\u7a81\u7136\u306e\u8ca0\u8377\u306e\u5897\u52a0\u3092\u3088\u308a\u52b9\u7387\u7684\u306b\u51e6\u7406\u3067\u304d\u308b\u306a\u3069\u3001\u3055\u307e\u3056\u307e\u306a\u6069\u6075\u304c\u5f97\u3089\u308c\u307e\u3059\u3002
"},{"location":"ja/#docker-kubernetes-go-100","title":"Docker \u3068 Kubernetes \u4e0a\u3067Go\u8a00\u8a9e\u3092\u5b9f\u884c\u3059\u308b\u3053\u3068\u306e\u5f71\u97ff\u3092\u7406\u89e3\u3057\u3066\u3044\u306a\u3044 (#100)","text":"\u8981\u7d04Docker \u3068 Kubernetes \u306b\u30c7\u30d7\u30ed\u30a4\u3059\u308b\u969b\u306e CPU \u30b9\u30ed\u30c3\u30c8\u30ea\u30f3\u30b0\u3092\u56de\u907f\u3059\u308b\u306b\u306f\u3001Go\u8a00\u8a9e\u304c CFS \u5bfe\u5fdc\u3067\u306f\u306a\u3044\u3053\u3068\u306b\u7559\u610f\u3057\u3066\u304f\u3060\u3055\u3044\u3002
"},{"location":"zh/","title":"100\u4e2aGo\u5e38\u89c1\u9519\u8bef\u53ca\u5982\u4f55\u907f\u514d","text":"JobsIs your company hiring? Sponsor the Chinese version of this repository and let a significant audience of Go developers (~1k unique visitors per week) know about your opportunities in this section.
"},{"location":"zh/#_1","title":"\u4ee3\u7801\u53ca\u5de5\u7a0b\u7ec4\u7ec7","text":""},{"location":"zh/#1","title":"\u610f\u5916\u7684\u53d8\u91cf\u9690\u85cf (#1)","text":"\u907f\u514d\u53d8\u91cf\u9690\u85cf\uff08\u5916\u90e8\u4f5c\u7528\u57df\u53d8\u91cf\u88ab\u5185\u90e8\u4f5c\u7528\u57df\u540c\u540d\u53d8\u91cf\u9690\u85cf\uff09\uff0c\u6709\u52a9\u4e8e\u907f\u514d\u53d8\u91cf\u5f15\u7528\u9519\u8bef\uff0c\u6709\u52a9\u4e8e\u4ed6\u4eba\u9605\u8bfb\u7406\u89e3\u3002
"},{"location":"zh/#2","title":"\u4e0d\u5fc5\u8981\u7684\u4ee3\u7801\u5d4c\u5957 (#2)","text":"\u907f\u514d\u4e0d\u5fc5\u8981\u7684\u3001\u8fc7\u591a\u7684\u5d4c\u5957\u5c42\u6b21\uff0c\u5e76\u4e14\u8ba9\u6b63\u5e38\u4ee3\u7801\u8def\u5f84\u5c3d\u91cf\u5de6\u5bf9\u9f50\uff08\u800c\u4e0d\u662f\u653e\u5728\u5206\u652f\u8def\u5f84\u4e2d\uff09\uff0c\u6709\u52a9\u4e8e\u6784\u5efa\u53ef\u8bfb\u6027\u66f4\u597d\u7684\u4ee3\u7801\u3002
"},{"location":"zh/#init-3","title":"\u8bef\u7528init\u51fd\u6570 (#3)","text":"\u521d\u59cb\u5316\u53d8\u91cf\u65f6\uff0c\u8bf7\u8bb0\u4f4f init \u51fd\u6570\u5177\u6709\u6709\u9650\u7684\u9519\u8bef\u5904\u7406\u80fd\u529b\uff0c\u5e76\u4e14\u4f1a\u4f7f\u72b6\u6001\u5904\u7406\u548c\u6d4b\u8bd5\u53d8\u5f97\u66f4\u52a0\u590d\u6742\u3002\u5728\u5927\u591a\u6570\u60c5\u51b5\u4e0b\uff0c\u521d\u59cb\u5316\u5e94\u8be5\u4f5c\u4e3a\u7279\u5b9a\u51fd\u6570\u6765\u5904\u7406\u3002
"},{"location":"zh/#getterssetters-4","title":"\u6ee5\u7528getters/setters (#4)","text":"\u5728Go\u8bed\u8a00\u4e2d\uff0c\u5f3a\u5236\u4f7f\u7528getter\u548csetter\u65b9\u6cd5\u5e76\u4e0d\u7b26\u5408Go\u60ef\u4f8b\u3002\u5728\u5b9e\u8df5\u4e2d\uff0c\u5e94\u8be5\u627e\u5230\u6548\u7387\u548c\u76f2\u76ee\u9075\u5faa\u67d0\u4e9b\u60ef\u7528\u6cd5\u4e4b\u95f4\u7684\u5e73\u8861\u70b9\u3002
"},{"location":"zh/#5","title":"\u63a5\u53e3\u6c61\u67d3 (#5)","text":"\u62bd\u8c61\u5e94\u8be5\u88ab\u53d1\u73b0\uff0c\u800c\u4e0d\u662f\u88ab\u521b\u9020\u3002\u4e3a\u4e86\u907f\u514d\u4e0d\u5fc5\u8981\u7684\u590d\u6742\u6027\uff0c\u9700\u8981\u65f6\u624d\u521b\u5efa\u63a5\u53e3\uff0c\u800c\u4e0d\u662f\u9884\u89c1\u5230\u9700\u8981\u5b83\uff0c\u6216\u8005\u81f3\u5c11\u53ef\u4ee5\u8bc1\u660e\u8fd9\u79cd\u62bd\u8c61\u662f\u6709\u4ef7\u503c\u7684\u3002
"},{"location":"zh/#6","title":"\u5c06\u63a5\u53e3\u5b9a\u4e49\u5728\u5b9e\u73b0\u65b9\u4e00\u4fa7 (#6)","text":"\u5c06\u63a5\u53e3\u4fdd\u7559\u5728\u5f15\u7528\u65b9\u4e00\u4fa7\uff08\u800c\u4e0d\u662f\u5b9e\u73b0\u65b9\u4e00\u4fa7\uff09\u53ef\u4ee5\u907f\u514d\u4e0d\u5fc5\u8981\u7684\u62bd\u8c61\u3002
"},{"location":"zh/#7","title":"\u5c06\u63a5\u53e3\u4f5c\u4e3a\u8fd4\u56de\u503c (#7)","text":"\u4e3a\u4e86\u907f\u514d\u5728\u7075\u6d3b\u6027\u65b9\u9762\u53d7\u5230\u9650\u5236\uff0c\u5927\u591a\u6570\u60c5\u51b5\u4e0b\u51fd\u6570\u4e0d\u5e94\u8be5\u8fd4\u56de\u63a5\u53e3\uff0c\u800c\u5e94\u8be5\u8fd4\u56de\u5177\u4f53\u7684\u5b9e\u73b0\u3002\u76f8\u53cd\uff0c\u51fd\u6570\u5e94\u8be5\u5c3d\u53ef\u80fd\u5730\u4f7f\u7528\u63a5\u53e3\u4f5c\u4e3a\u53c2\u6570\u3002
"},{"location":"zh/#any-8","title":"any
\u6ca1\u4f20\u9012\u4efb\u4f55\u4fe1\u606f (#8)","text":"\u53ea\u6709\u5728\u9700\u8981\u63a5\u53d7\u6216\u8fd4\u56de\u4efb\u610f\u7c7b\u578b\u65f6\uff0c\u624d\u4f7f\u7528 any
\uff0c\u4f8b\u5982 json.Marshal
\u3002\u5176\u4ed6\u60c5\u51b5\u4e0b\uff0c\u56e0\u4e3a any
\u4e0d\u63d0\u4f9b\u6709\u610f\u4e49\u7684\u4fe1\u606f\uff0c\u53ef\u80fd\u4f1a\u5bfc\u81f4\u7f16\u8bd1\u65f6\u95ee\u9898\uff0c\u5982\u5141\u8bb8\u8c03\u7528\u8005\u8c03\u7528\u65b9\u6cd5\u5904\u7406\u4efb\u610f\u7c7b\u578b\u6570\u636e\u3002
\u4f7f\u7528\u6cdb\u578b\uff0c\u53ef\u4ee5\u901a\u8fc7\u7c7b\u578b\u53c2\u6570\u5206\u79bb\u5177\u4f53\u7684\u6570\u636e\u7c7b\u578b\u548c\u884c\u4e3a\uff0c\u907f\u514d\u5199\u5f88\u591a\u91cd\u590d\u5ea6\u5f88\u9ad8\u7684\u4ee3\u7801\u3002\u7136\u800c\uff0c\u4e0d\u8981\u8fc7\u65e9\u5730\u4f7f\u7528\u6cdb\u578b\u3001\u7c7b\u578b\u53c2\u6570\uff0c\u53ea\u6709\u5728\u4f60\u770b\u5230\u771f\u6b63\u9700\u8981\u65f6\u624d\u4f7f\u7528\u3002\u5426\u5219\uff0c\u5b83\u4eec\u4f1a\u5f15\u5165\u4e0d\u5fc5\u8981\u7684\u62bd\u8c61\u548c\u590d\u6742\u6027\u3002
"},{"location":"zh/#10","title":"\u672a\u610f\u8bc6\u5230\u7c7b\u578b\u5d4c\u5957\u7684\u53ef\u80fd\u95ee\u9898 (#10)","text":"\u4f7f\u7528\u7c7b\u578b\u5d4c\u5957\u4e5f\u53ef\u4ee5\u907f\u514d\u5199\u4e00\u4e9b\u91cd\u590d\u4ee3\u7801\uff0c\u7136\u800c\uff0c\u5728\u4f7f\u7528\u65f6\u9700\u8981\u786e\u4fdd\u4e0d\u4f1a\u5bfc\u81f4\u4e0d\u5408\u7406\u7684\u53ef\u89c1\u6027\u95ee\u9898\uff0c\u6bd4\u5982\u6709\u4e9b\u5b57\u6bb5\u5e94\u8be5\u5bf9\u5916\u9690\u85cf\u4e0d\u5e94\u8be5\u88ab\u66b4\u6f0f\u3002
"},{"location":"zh/#function-option-11","title":"\u4e0d\u4f7f\u7528function option\u6a21\u5f0f (#11)","text":"\u4e3a\u4e86\u8bbe\u8ba1\u5e76\u63d0\u4f9b\u66f4\u53cb\u597d\u7684API\uff08\u53ef\u9009\u53c2\u6570\uff09\uff0c\u4e3a\u4e86\u66f4\u597d\u5730\u5904\u7406\u9009\u9879\uff0c\u5e94\u8be5\u4f7f\u7528function option\u6a21\u5f0f\u3002
"},{"location":"zh/#12","title":"\u5de5\u7a0b\u7ec4\u7ec7\u4e0d\u5408\u7406 (\u5de5\u7a0b\u7ed3\u6784\u548c\u5305\u7684\u7ec4\u7ec7) (#12)","text":"\u9075\u5faa\u50cf project-layout \u7684\u5efa\u8bae\u6765\u7ec4\u7ec7Go\u5de5\u7a0b\u662f\u4e00\u4e2a\u4e0d\u9519\u7684\u65b9\u6cd5\uff0c\u7279\u522b\u662f\u4f60\u6b63\u5728\u5bfb\u627e\u4e00\u4e9b\u7c7b\u4f3c\u7684\u7ecf\u9a8c\u3001\u60ef\u4f8b\u6765\u7ec4\u7ec7\u4e00\u4e2a\u65b0\u7684Go\u5de5\u7a0b\u7684\u65f6\u5019\u3002
"},{"location":"zh/#13","title":"\u521b\u5efa\u5de5\u5177\u5305 (#13)","text":"\u547d\u540d\u662f\u8f6f\u4ef6\u8bbe\u8ba1\u5f00\u53d1\u4e2d\u975e\u5e38\u91cd\u8981\u7684\u4e00\u4e2a\u90e8\u5206\uff0c\u521b\u5efa\u4e00\u4e9b\u540d\u5982 common
\u3001util
\u3001shared
\u4e4b\u7c7b\u7684\u5305\u540d\u5e76\u4e0d\u4f1a\u7ed9\u8bfb\u8005\u5e26\u6765\u592a\u5927\u4ef7\u503c\uff0c\u5e94\u8be5\u5c06\u8fd9\u4e9b\u5305\u540d\u91cd\u6784\u4e3a\u66f4\u6e05\u6670\u3001\u66f4\u805a\u7126\u7684\u5305\u540d\u3002
\u4e3a\u4e86\u907f\u514d\u53d8\u91cf\u540d\u548c\u5305\u540d\u4e4b\u95f4\u7684\u51b2\u7a81\uff0c\u5bfc\u81f4\u6df7\u6dc6\u6216\u751a\u81f3\u9519\u8bef\uff0c\u5e94\u4e3a\u6bcf\u4e2a\u53d8\u91cf\u548c\u5305\u4f7f\u7528\u552f\u4e00\u7684\u540d\u79f0\u3002\u5982\u679c\u8fd9\u4e0d\u53ef\u884c\uff0c\u53ef\u4ee5\u8003\u8651\u4f7f\u7528\u5bfc\u5165\u522b\u540d import importAlias 'importPath'
\uff0c\u4ee5\u533a\u5206\u5305\u540d\u548c\u53d8\u91cf\u540d\uff0c\u6216\u8005\u8003\u8651\u4e00\u4e2a\u66f4\u597d\u7684\u53d8\u91cf\u540d\u3002
\u4e3a\u4e86\u8ba9\u4f7f\u7528\u65b9\u3001\u7ef4\u62a4\u4eba\u5458\u80fd\u66f4\u6e05\u6670\u5730\u4e86\u89e3\u4f60\u7684\u4ee3\u7801\u7684\u610f\u56fe\uff0c\u5bfc\u51fa\u7684\u5143\u7d20\uff08\u51fd\u6570\u3001\u7c7b\u578b\u3001\u5b57\u6bb5\uff09\u9700\u8981\u6dfb\u52a0godoc\u6ce8\u91ca\u3002
"},{"location":"zh/#linters-16","title":"\u4e0d\u4f7f\u7528linters\u68c0\u67e5 (#16)","text":"\u4e3a\u4e86\u6539\u5584\u4ee3\u7801\u8d28\u91cf\u3001\u6574\u4f53\u4ee3\u7801\u7684\u4e00\u81f4\u6027\uff0c\u5e94\u8be5\u4f7f\u7528linters\u3001formatters\u3002
"},{"location":"zh/#_2","title":"\u6570\u636e\u7c7b\u578b","text":""},{"location":"zh/#17","title":"\u516b\u8fdb\u5236\u5b57\u9762\u91cf\u5f15\u53d1\u7684\u56f0\u60d1 (#17)","text":"\u5728\u9605\u8bfb\u73b0\u6709\u4ee3\u7801\u65f6\uff0c\u8bf7\u8bb0\u4f4f\u4ee5 0 \u5f00\u5934\u7684\u6574\u6570\u5b57\u9762\u91cf\u662f\u516b\u8fdb\u5236\u6570\u3002\u6b64\u5916\uff0c\u4e3a\u4e86\u63d0\u9ad8\u53ef\u8bfb\u6027\uff0c\u53ef\u4ee5\u901a\u8fc7\u5728\u524d\u9762\u52a0\u4e0a 0o \u6765\u663e\u5f0f\u5730\u8868\u793a\u516b\u8fdb\u5236\u6574\u6570\u3002
"},{"location":"zh/#18","title":"\u672a\u6ce8\u610f\u53ef\u80fd\u7684\u6574\u6570\u6ea2\u51fa (#18)","text":"\u5728 Go \u4e2d\u6574\u6570\u4e0a\u6ea2\u51fa\u548c\u4e0b\u6ea2\u662f\u9759\u9ed8\u5904\u7406\u7684\uff0c\u6240\u4ee5\u4f60\u53ef\u4ee5\u5b9e\u73b0\u81ea\u5df1\u7684\u51fd\u6570\u6765\u6355\u83b7\u5b83\u4eec\u3002
"},{"location":"zh/#19","title":"\u6ca1\u6709\u900f\u5f7b\u7406\u89e3\u6d6e\u70b9\u6570 (#19)","text":"\u6bd4\u8f83\u6d6e\u70b9\u6570\u65f6\uff0c\u901a\u8fc7\u6bd4\u8f83\u4e8c\u8005\u7684delta\u503c\u662f\u5426\u4ecb\u4e8e\u4e00\u5b9a\u7684\u8303\u56f4\u5185\uff0c\u80fd\u8ba9\u4f60\u5199\u51fa\u53ef\u79fb\u690d\u6027\u66f4\u597d\u7684\u4ee3\u7801\u3002
\u5728\u8fdb\u884c\u52a0\u6cd5\u6216\u51cf\u6cd5\u65f6\uff0c\u5c06\u5177\u6709\u76f8\u4f3c\u6570\u91cf\u7ea7\u7684\u64cd\u4f5c\u5206\u6210\u540c\u4e00\u7ec4\u4ee5\u63d0\u9ad8\u7cbe\u5ea6 (\u8fc7\u65e9\u6307\u6570\u5bf9\u9f50\u4e22\u5931\u7cbe\u5ea6)\u3002\u6b64\u5916\uff0c\u5728\u8fdb\u884c\u52a0\u6cd5\u548c\u51cf\u6cd5\u4e4b\u524d\uff0c\u5e94\u5148\u8fdb\u884c\u4e58\u6cd5\u548c\u9664\u6cd5 (\u52a0\u51cf\u6cd5\u8bef\u5dee\u4f1a\u88ab\u4e58\u9664\u653e\u5927)\u3002
"},{"location":"zh/#slice-20","title":"\u4e0d\u7406\u89e3slice\u7684\u957f\u5ea6\u548c\u5bb9\u91cf (#20)","text":"\u7406\u89e3slice\u7684\u957f\u5ea6\u548c\u5bb9\u91cf\u7684\u533a\u522b\uff0c\u662f\u4e00\u4e2aGo\u5f00\u53d1\u8005\u7684\u6838\u5fc3\u77e5\u8bc6\u70b9\u4e4b\u4e00\u3002slice\u7684\u957f\u5ea6\u6307\u7684\u662fslice\u5df2\u7ecf\u5b58\u50a8\u7684\u5143\u7d20\u7684\u6570\u91cf\uff0c\u800c\u5bb9\u91cf\u6307\u7684\u662fslice\u5f53\u524d\u5e95\u5c42\u5f00\u8f9f\u7684\u6570\u7ec4\u6700\u591a\u80fd\u5bb9\u7eb3\u7684\u5143\u7d20\u7684\u6570\u91cf\u3002
"},{"location":"zh/#slice-21","title":"\u4e0d\u9ad8\u6548\u7684slice\u521d\u59cb\u5316 (#21)","text":"\u5f53\u521b\u5efa\u4e00\u4e2aslice\u65f6\uff0c\u5982\u679c\u5176\u957f\u5ea6\u53ef\u4ee5\u9884\u5148\u786e\u5b9a\uff0c\u90a3\u4e48\u53ef\u4ee5\u5728\u5b9a\u4e49\u65f6\u6307\u5b9a\u5b83\u7684\u957f\u5ea6\u548c\u5bb9\u91cf\u3002\u8fd9\u53ef\u4ee5\u6539\u5584\u540e\u671fappend\u65f6\u4e00\u6b21\u6216\u8005\u591a\u6b21\u7684\u5185\u5b58\u5206\u914d\u64cd\u4f5c\uff0c\u4ece\u800c\u6539\u5584\u6027\u80fd\u3002\u5bf9\u4e8emap\u7684\u521d\u59cb\u5316\u4e5f\u662f\u8fd9\u6837\u7684\u3002
"},{"location":"zh/#nilslice-22","title":"\u56f0\u60d1\u4e8enil\u548c\u7a7aslice (#22)","text":"\u4e3a\u4e86\u907f\u514d\u5e38\u89c1\u7684\u5bf9nil\u548cempty slice\u5904\u7406\u884c\u4e3a\u7684\u6df7\u6dc6\uff0c\u4f8b\u5982\u5728\u4f7f\u7528 encoding/json \u6216 reflect \u5305\u65f6\uff0c\u4f60\u9700\u8981\u7406\u89e3 nil \u548c empty slice\u7684\u533a\u522b\u3002\u4e24\u8005\u90fd\u662f\u957f\u5ea6\u4e3a\u96f6\u3001\u5bb9\u91cf\u4e3a\u96f6\u7684\u5207\u7247\uff0c\u4f46\u662f nil \u5207\u7247\u4e0d\u9700\u8981\u5206\u914d\u5185\u5b58\u3002
"},{"location":"zh/#slice-23","title":"\u6ca1\u6709\u9002\u5f53\u68c0\u67e5slice\u662f\u5426\u4e3a\u7a7a (#23)","text":"\u68c0\u67e5\u4e00\u4e2aslice\u7684\u662f\u5426\u5305\u542b\u4efb\u4f55\u5143\u7d20\uff0c\u53ef\u4ee5\u68c0\u67e5\u5176\u957f\u5ea6\uff0c\u4e0d\u7ba1slice\u662fnil\u8fd8\u662fempty\uff0c\u68c0\u67e5\u957f\u5ea6\u90fd\u662f\u6709\u6548\u7684\u3002\u8fd9\u4e2a\u68c0\u67e5\u65b9\u6cd5\u4e5f\u9002\u7528\u4e8emap\u3002
\u4e3a\u4e86\u8bbe\u8ba1\u66f4\u660e\u786e\u7684API\uff0cAPI\u4e0d\u5e94\u533a\u5206nil\u548c\u7a7a\u5207\u7247\u3002
"},{"location":"zh/#slice-24","title":"\u6ca1\u6709\u6b63\u786e\u62f7\u8d1dslice (#24)","text":"\u4f7f\u7528 copy
\u62f7\u8d1d\u4e00\u4e2aslice\u5143\u7d20\u5230\u53e6\u4e00\u4e2aslice\u65f6\uff0c\u9700\u8981\u8bb0\u5f97\uff0c\u5b9e\u9645\u62f7\u8d1d\u7684\u5143\u7d20\u6570\u91cf\u662f\u4e8c\u8005slice\u957f\u5ea6\u4e2d\u7684\u8f83\u5c0f\u503c\u3002
\u5982\u679c\u4e24\u4e2a\u4e0d\u540c\u7684\u51fd\u6570\u64cd\u4f5c\u7684slice\u590d\u7528\u4e86\u76f8\u540c\u7684\u5e95\u5c42\u6570\u7ec4\uff0c\u5b83\u4eec\u5bf9slice\u6267\u884cappend\u64cd\u4f5c\u65f6\u53ef\u80fd\u4f1a\u4ea7\u751f\u51b2\u7a81\u3002\u4f7f\u7528copy\u6765\u5b8c\u6574\u590d\u5236\u4e00\u4e2aslice\u6216\u8005\u4f7f\u7528\u5b8c\u6574\u7684slice\u8868\u8fbe\u5f0f[low:high:max]\u9650\u5236\u6700\u5927\u5bb9\u91cf\uff0c\u6709\u52a9\u4e8e\u907f\u514d\u4ea7\u751f\u51b2\u7a81\u3002\u5f53\u60f3\u5bf9\u4e00\u4e2a\u5927slice\u8fdb\u884cshrink\u64cd\u4f5c\u65f6\uff0c\u4e24\u79cd\u65b9\u5f0f\u4e2d\uff0c\u53ea\u6709copy\u624d\u53ef\u4ee5\u907f\u514d\u5185\u5b58\u6cc4\u6f0f\u3002
"},{"location":"zh/#slice-26","title":"slice\u548c\u5185\u5b58\u6cc4\u6f0f (#26)","text":"\u5bf9\u4e8eslice\u5143\u7d20\u4e3a\u6307\u9488\uff0c\u6216\u8005slice\u5143\u7d20\u4e3astruct\u4f46\u662f\u8be5struct\u542b\u6709\u6307\u9488\u5b57\u6bb5\uff0c\u5f53\u901a\u8fc7slice[low:high]\u64cd\u4f5c\u53d6subslice\u65f6\uff0c\u5bf9\u4e8e\u90a3\u4e9b\u4e0d\u53ef\u8bbf\u95ee\u7684\u5143\u7d20\u53ef\u4ee5\u663e\u793a\u8bbe\u7f6e\u4e3anil\u6765\u907f\u514d\u5185\u5b58\u6cc4\u9732\u3002
"},{"location":"zh/#map-27","title":"\u4e0d\u9ad8\u6548\u7684map\u521d\u59cb\u5316 (#27)","text":"\u89c1 #21.
"},{"location":"zh/#map-28","title":"map\u548c\u5185\u5b58\u6cc4\u6f0f (#28)","text":"\u4e00\u4e2amap\u7684buckets\u5360\u7528\u7684\u5185\u5b58\u53ea\u4f1a\u589e\u957f\uff0c\u4e0d\u4f1a\u7f29\u51cf\u3002\u56e0\u6b64\uff0c\u5982\u679c\u5b83\u5bfc\u81f4\u4e86\u4e00\u4e9b\u5185\u5b58\u5360\u7528\u7684\u95ee\u9898\uff0c\u4f60\u9700\u8981\u5c1d\u8bd5\u4e0d\u540c\u7684\u9009\u9879\u6765\u89e3\u51b3\uff0c\u6bd4\u5982\u91cd\u65b0\u521b\u5efa\u4e00\u4e2amap\u4ee3\u66ff\u539f\u6765\u7684\uff08\u539f\u6765\u7684map\u4f1a\u88abGC\u6389\uff09\uff0c\u6216\u8005map[keyType]valueType\u4e2d\u7684valueType\u4f7f\u7528\u6307\u9488\u4ee3\u66ff\u957f\u5ea6\u56fa\u5b9a\u7684\u6570\u7ec4\u6216\u8005sliceHeader\u6765\u7f13\u89e3\u8fc7\u591a\u7684\u5185\u5b58\u5360\u7528\u3002
"},{"location":"zh/#29","title":"\u4e0d\u6b63\u786e\u7684\u503c\u6bd4\u8f83 (#29)","text":"Go\u4e2d\u6bd4\u8f83\u4e24\u4e2a\u7c7b\u578b\u503c\u65f6\uff0c\u5982\u679c\u662f\u53ef\u6bd4\u8f83\u7c7b\u578b\uff0c\u90a3\u4e48\u53ef\u4ee5\u4f7f\u7528 ==
\u6216\u8005 !=
\u8fd0\u7b97\u7b26\u8fdb\u884c\u6bd4\u8f83\uff0c\u6bd4\u5982\uff1abooleans\u3001numerals\u3001strings\u3001pointers\u3001channels\uff0c\u4ee5\u53ca\u5b57\u6bb5\u5168\u90e8\u662f\u53ef\u6bd4\u8f83\u7c7b\u578b\u7684structs\u3002\u5176\u4ed6\u60c5\u51b5\u4e0b\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528 reflect.DeepEqual
\u6765\u6bd4\u8f83\uff0c\u7528\u53cd\u5c04\u7684\u8bdd\u4f1a\u727a\u7272\u4e00\u70b9\u6027\u80fd\uff0c\u4e5f\u53ef\u4ee5\u4f7f\u7528\u81ea\u5b9a\u4e49\u7684\u5b9e\u73b0\u548c\u5176\u4ed6\u5e93\u6765\u5b8c\u6210\u3002
range
\u5faa\u73af\u53d8\u91cf\u662f\u4e00\u4e2a\u62f7\u8d1d (#30)","text":"range
\u5faa\u73af\u4e2d\u7684\u5faa\u73af\u53d8\u91cf\u662f\u904d\u5386\u5bb9\u5668\u4e2d\u5143\u7d20\u503c\u7684\u4e00\u4e2a\u62f7\u8d1d\u3002\u56e0\u6b64\uff0c\u5982\u679c\u5143\u7d20\u503c\u662f\u4e00\u4e2astruct\u5e76\u4e14\u60f3\u5728 range
\u4e2d\u4fee\u6539\u5b83\uff0c\u53ef\u4ee5\u901a\u8fc7\u7d22\u5f15\u503c\u6765\u8bbf\u95ee\u5e76\u4fee\u6539\u5b83\uff0c\u6216\u8005\u4f7f\u7528\u7ecf\u5178\u7684for\u5faa\u73af+\u7d22\u5f15\u503c\u7684\u5199\u6cd5\uff08\u9664\u975e\u904d\u5386\u7684\u5143\u7d20\u662f\u4e00\u4e2a\u6307\u9488\uff09\u3002
range
\u5faa\u73af\u4e2d\u8fed\u4ee3\u76ee\u6807\u503c\u7684\u8ba1\u7b97\u65b9\u5f0f (channels \u548c arrays) (#31)","text":"\u4f20\u9012\u7ed9 range
\u64cd\u4f5c\u7684\u8fed\u4ee3\u76ee\u6807\u5bf9\u5e94\u7684\u8868\u8fbe\u5f0f\u7684\u503c\uff0c\u53ea\u4f1a\u5728\u5faa\u73af\u6267\u884c\u524d\u88ab\u8ba1\u7b97\u4e00\u6b21\uff0c\u7406\u89e3\u8fd9\u4e2a\u6709\u52a9\u4e8e\u907f\u514d\u72af\u4e00\u4e9b\u5e38\u89c1\u7684\u9519\u8bef\uff0c\u4f8b\u5982\u4e0d\u9ad8\u6548\u7684channel\u8d4b\u503c\u64cd\u4f5c\u3001slice\u8fed\u4ee3\u64cd\u4f5c\u3002
range
\u5faa\u73af\u4e2d\u6307\u9488\u5143\u7d20\u7684\u5f71\u54cd range
loops (#32)","text":"\u8fd9\u91cc\u5176\u5b9e\u5f3a\u8c03\u7684\u662f range
\u8fed\u4ee3\u8fc7\u7a0b\u4e2d\uff0c\u8fed\u4ee3\u53d8\u91cf\u5b9e\u9645\u4e0a\u662f\u4e00\u4e2a\u62f7\u8d1d\uff0c\u5047\u8bbe\u7ed9\u53e6\u5916\u4e00\u4e2a\u5bb9\u5668\u5143\u7d20\uff08\u6307\u9488\u7c7b\u578b\uff09\u8d4b\u503c\uff0c\u4e14\u9700\u8981\u5bf9\u8fed\u4ee3\u53d8\u91cf\u53d6\u5730\u5740\u8f6c\u6362\u6210\u6307\u9488\u518d\u8d4b\u503c\u7684\u8bdd\uff0c\u8fd9\u91cc\u6f5c\u85cf\u7740\u4e00\u4e2a\u9519\u8bef\uff0c\u5c31\u662ffor\u5faa\u73af\u8fed\u4ee3\u53d8\u91cf\u662f per-variable-per-loop \u800c\u4e0d\u662f per-variable-per-iteration\u3002\u5982\u679c\u662f\u901a\u8fc7\u5c40\u90e8\u53d8\u91cf\uff08\u7528\u8fed\u4ee3\u53d8\u91cf\u6765\u521d\u59cb\u5316\uff09\u6216\u8005\u4f7f\u7528\u7d22\u5f15\u503c\u6765\u76f4\u63a5\u5f15\u7528\u8fed\u4ee3\u7684\u5143\u7d20\uff0c\u5c06\u6709\u52a9\u4e8e\u907f\u514d\u62f7\u8d1d\u6307\u9488(\u8fed\u4ee3\u53d8\u91cf\u7684\u5730\u5740)\u4e4b\u7c7b\u7684bug\u3002
\u4f7f\u7528map\u65f6\uff0c\u4e3a\u4e86\u80fd\u5f97\u5230\u786e\u5b9a\u4e00\u81f4\u7684\u7ed3\u679c\uff0c\u5e94\u8be5\u8bb0\u4f4fGo\u4e2d\u7684map\u6570\u636e\u7ed3\u6784\uff1a * \u4e0d\u4f1a\u6309\u7167key\u5bf9data\u8fdb\u884c\u6392\u5e8f\uff0c\u904d\u5386\u65f6\u4e0d\u662f\u6309key\u6709\u5e8f\u7684\uff1b * \u904d\u5386\u65f6\u7684\u987a\u5e8f\uff0c\u4e5f\u4e0d\u662f\u6309\u7167\u63d2\u5165\u65f6\u7684\u987a\u5e8f\uff1b * \u6ca1\u6709\u4e00\u4e2a\u786e\u5b9a\u6027\u7684\u904d\u5386\u987a\u5e8f\uff0c\u6bcf\u6b21\u904d\u5386\u987a\u5e8f\u662f\u4e0d\u540c\u7684\uff1b * \u4e0d\u80fd\u4fdd\u8bc1\u8fed\u4ee3\u8fc7\u7a0b\u4e2d\u65b0\u63d2\u5165\u7684\u5143\u7d20\uff0c\u5728\u5f53\u524d\u8fed\u4ee3\u4e2d\u80fd\u591f\u88ab\u904d\u5386\u5230\uff1b
"},{"location":"zh/#break-34","title":"\u5ffd\u7565\u4e86break
\u8bed\u53e5\u662f\u5982\u4f55\u5de5\u4f5c\u7684 (#34)","text":"\u914d\u5408label\u4f7f\u7528 break
\u548c continue
\uff0c\u80fd\u591f\u8df3\u8fc7\u4e00\u4e2a\u7279\u5b9a\u7684\u8bed\u53e5\uff0c\u5728\u67d0\u4e9b\u5faa\u73af\u4e2d\u5b58\u5728 switch
\u548cselect
\u8bed\u53e5\u7684\u573a\u666f\u4e2d\u5c31\u6bd4\u8f83\u6709\u5e2e\u52a9\u3002
defer
(#35)","text":"\u5728\u5faa\u73af\u4e2d\u4f7f\u7528defer\u4e0d\u80fd\u5728\u6bcf\u8f6e\u8fed\u4ee3\u7ed3\u675f\u65f6\u6267\u884cdefer\u8bed\u53e5\uff0c\u4f46\u662f\u5c06\u5faa\u73af\u903b\u8f91\u63d0\u53d6\u5230\u51fd\u6570\u5185\u90e8\u4f1a\u5728\u6bcf\u6b21\u8fed\u4ee3\u7ed3\u675f\u65f6\u6267\u884c defer \u8bed\u53e5\u3002
"},{"location":"zh/#_4","title":"\u5b57\u7b26\u4e32","text":""},{"location":"zh/#rune-36","title":"\u6ca1\u6709\u7406\u89e3rune (#36)","text":"\u7406\u89e3rune\u7c7b\u578b\u5bf9\u5e94\u7684\u662f\u4e00\u4e2aunicode\u7801\u70b9\uff0c\u6bcf\u4e00\u4e2aunicode\u7801\u70b9\u5176\u5b9e\u662f\u4e00\u4e2a\u591a\u5b57\u8282\u7684\u5e8f\u5217\uff0c\u4e0d\u662f\u4e00\u4e2abyte\u3002\u8fd9\u5e94\u8be5\u662fGo\u5f00\u53d1\u8005\u7684\u6838\u5fc3\u77e5\u8bc6\u70b9\u4e4b\u4e00\uff0c\u7406\u89e3\u4e86\u8fd9\u4e2a\u6709\u52a9\u4e8e\u66f4\u51c6\u786e\u5730\u5904\u7406\u5b57\u7b26\u4e32\u3002
"},{"location":"zh/#37","title":"\u4e0d\u6b63\u786e\u7684\u5b57\u7b26\u4e32\u904d\u5386 (#37)","text":"\u4f7f\u7528 range
\u64cd\u4f5c\u7b26\u5bf9\u4e00\u4e2astring\u8fdb\u884c\u904d\u5386\u5b9e\u9645\u4e0a\u662f\u5bf9string\u5bf9\u5e94\u7684 []rune
\u8fdb\u884c\u904d\u5386\uff0c\u8fed\u4ee3\u53d8\u91cf\u4e2d\u7684\u7d22\u5f15\u503c\uff0c\u8868\u793a\u7684\u5f53\u524drune\u5bf9\u5e94\u7684 []byte
\u5728\u6574\u4e2a []byte(string)
\u4e2d\u7684\u8d77\u59cb\u7d22\u5f15\u3002\u5982\u679c\u8981\u8bbf\u95eestring\u4e2d\u7684\u67d0\u4e00\u4e2arune\uff08\u6bd4\u5982\u7b2c\u4e09\u4e2a\uff09\uff0c\u9996\u5148\u8981\u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a []rune
\u7136\u540e\u518d\u6309\u7d22\u5f15\u503c\u8bbf\u95ee\u3002
strings.TrimRight
/strings.TrimLeft
\u79fb\u9664\u5728\u5b57\u7b26\u4e32\u5c3e\u90e8\u6216\u8005\u5f00\u5934\u51fa\u73b0\u7684\u4e00\u4e9brunes\uff0c\u51fd\u6570\u4f1a\u6307\u5b9a\u4e00\u4e2arune\u96c6\u5408\uff0c\u51fa\u73b0\u5728\u96c6\u5408\u4e2d\u7684rune\u5c06\u88ab\u4ece\u5b57\u7b26\u4e32\u79fb\u9664\u3002\u800c strings.TrimSuffix
/strings.TrimPrefix
\u662f\u79fb\u9664\u5b57\u7b26\u4e32\u7684\u4e00\u4e2a\u540e\u7f00/\u524d\u7f00\u3002
\u5bf9\u4e00\u4e2a\u5b57\u7b26\u4e32\u5217\u8868\u8fdb\u884c\u904d\u5386\u62fc\u63a5\u64cd\u4f5c\uff0c\u5e94\u8be5\u901a\u8fc7 strings.Builder
\u6765\u5b8c\u6210\uff0c\u4ee5\u907f\u514d\u6bcf\u6b21\u8fed\u4ee3\u62fc\u63a5\u65f6\u90fd\u5206\u914d\u4e00\u4e2a\u65b0\u7684string\u5bf9\u8c61\u51fa\u6765\u3002
bytes
\u5305\u63d0\u4f9b\u4e86\u4e00\u4e9b\u548c strings
\u5305\u76f8\u4f3c\u7684\u64cd\u4f5c\uff0c\u53ef\u4ee5\u5e2e\u52a9\u907f\u514d []byte/string \u4e4b\u95f4\u7684\u8f6c\u6362\u3002
\u4f7f\u7528\u4e00\u4e2a\u5b50\u5b57\u7b26\u4e32\u7684\u62f7\u8d1d\uff0c\u6709\u52a9\u4e8e\u907f\u514d\u5185\u5b58\u6cc4\u6f0f\uff0c\u56e0\u4e3a\u5bf9\u4e00\u4e2a\u5b57\u7b26\u4e32\u7684s[low:high]\u64cd\u4f5c\u8fd4\u56de\u7684\u5b50\u5b57\u7b26\u4e32\uff0c\u5176\u4f7f\u7528\u4e86\u548c\u539f\u5b57\u7b26\u4e32s\u76f8\u540c\u7684\u5e95\u5c42\u6570\u7ec4\u3002
"},{"location":"zh/#_5","title":"\u51fd\u6570\u548c\u65b9\u6cd5","text":""},{"location":"zh/#42","title":"\u4e0d\u77e5\u9053\u4f7f\u7528\u54ea\u79cd\u63a5\u6536\u5668\u7c7b\u578b (#42)","text":"\u5bf9\u4e8e\u63a5\u6536\u5668\u7c7b\u578b\u662f\u91c7\u7528value\u7c7b\u578b\u8fd8\u662fpointer\u7c7b\u578b\uff0c\u5e94\u8be5\u53d6\u51b3\u4e8e\u4e0b\u9762\u8fd9\u51e0\u79cd\u56e0\u7d20\uff0c\u6bd4\u5982\uff1a\u65b9\u6cd5\u5185\u662f\u5426\u4f1a\u5bf9\u5b83\u8fdb\u884c\u4fee\u6539\uff0c\u5b83\u662f\u5426\u5305\u542b\u4e86\u4e00\u4e2a\u4e0d\u80fd\u88ab\u62f7\u8d1d\u7684\u5b57\u6bb5\uff0c\u4ee5\u53ca\u5b83\u8868\u793a\u7684\u5bf9\u8c61\u6709\u591a\u5927\u3002\u5982\u679c\u6709\u7591\u95ee\uff0c\u63a5\u6536\u5668\u53ef\u4ee5\u8003\u8651\u4f7f\u7528pointer\u7c7b\u578b\u3002
"},{"location":"zh/#43","title":"\u4ece\u4e0d\u4f7f\u7528\u547d\u540d\u7684\u8fd4\u56de\u503c (#43)","text":"\u4f7f\u7528\u547d\u540d\u7684\u8fd4\u56de\u503c\uff0c\u662f\u4e00\u79cd\u6709\u6548\u6539\u5584\u51fd\u6570\u3001\u65b9\u6cd5\u53ef\u8bfb\u6027\u7684\u65b9\u6cd5\uff0c\u7279\u522b\u662f\u8fd4\u56de\u503c\u5217\u8868\u4e2d\u6709\u591a\u4e2a\u7c7b\u578b\u76f8\u540c\u7684\u53c2\u6570\u3002\u53e6\u5916\uff0c\u56e0\u4e3a\u8fd4\u56de\u503c\u5217\u8868\u4e2d\u7684\u53c2\u6570\u662f\u7ecf\u8fc7\u96f6\u503c\u521d\u59cb\u5316\u8fc7\u7684\uff0c\u67d0\u4e9b\u573a\u666f\u4e0b\u4e5f\u4f1a\u7b80\u5316\u51fd\u6570\u3001\u65b9\u6cd5\u7684\u5b9e\u73b0\u3002\u4f46\u662f\u9700\u8981\u6ce8\u610f\u5b83\u7684\u4e00\u4e9b\u6f5c\u5728\u526f\u4f5c\u7528\u3002
"},{"location":"zh/#44","title":"\u4f7f\u7528\u547d\u540d\u7684\u8fd4\u56de\u503c\u65f6\u9884\u671f\u5916\u7684\u526f\u4f5c\u7528 (#44)","text":"\u89c1 #43.
\u4f7f\u7528\u547d\u540d\u7684\u8fd4\u56de\u503c\uff0c\u56e0\u4e3a\u5b83\u5df2\u7ecf\u88ab\u521d\u59cb\u5316\u4e86\u96f6\u503c\uff0c\u9700\u8981\u6ce8\u610f\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\u5f02\u5e38\u8fd4\u56de\u65f6\u662f\u5426\u9700\u8981\u7ed9\u5b83\u8d4b\u4e88\u4e00\u4e2a\u4e0d\u540c\u7684\u503c\uff0c\u6bd4\u5982\u8fd4\u56de\u503c\u5217\u8868\u5b9a\u4e49\u4e86\u4e00\u4e2a\u6709\u540d\u53c2\u6570 err error
\uff0c\u9700\u8981\u6ce8\u610f return err
\u65f6\u662f\u5426\u6b63\u786e\u5730\u5bf9 err
\u8fdb\u884c\u4e86\u8d4b\u503c\u3002
\u5f53\u8fd4\u56de\u4e00\u4e2ainterface\u53c2\u6570\u65f6\uff0c\u9700\u8981\u5c0f\u5fc3\uff0c\u4e0d\u8981\u8fd4\u56de\u4e00\u4e2anil\u6307\u9488\uff0c\u800c\u662f\u5e94\u8be5\u663e\u793a\u8fd4\u56de\u4e00\u4e2anil\u503c\u3002\u5426\u5219\uff0c\u53ef\u80fd\u4f1a\u53d1\u751f\u4e00\u4e9b\u9884\u671f\u5916\u7684\u95ee\u9898\uff0c\u56e0\u4e3a\u8c03\u7528\u65b9\u4f1a\u6536\u5230\u4e00\u4e2a\u975enil\u7684\u503c\u3002
"},{"location":"zh/#46","title":"\u4f7f\u7528\u6587\u4ef6\u540d\u4f5c\u4e3a\u51fd\u6570\u5165\u53c2 (#46)","text":"\u8bbe\u8ba1\u51fd\u6570\u65f6\u4f7f\u7528 io.Reader
\u7c7b\u578b\u4f5c\u4e3a\u5165\u53c2\uff0c\u800c\u4e0d\u662f\u6587\u4ef6\u540d\uff0c\u5c06\u6709\u52a9\u4e8e\u6539\u5584\u51fd\u6570\u7684\u53ef\u590d\u7528\u6027\u3001\u6613\u6d4b\u8bd5\u6027\u3002
defer
\u8bed\u53e5\u4e2d\u53c2\u6570\u3001\u63a5\u6536\u5668\u503c\u7684\u8ba1\u7b97\u65b9\u5f0f (\u53c2\u6570\u503c\u8ba1\u7b97, \u6307\u9488, \u548c value\u7c7b\u578b\u63a5\u6536\u5668) (#47)","text":"\u4e3a\u4e86\u907f\u514d defer
\u8bed\u53e5\u6267\u884c\u65f6\u5c31\u7acb\u5373\u8ba1\u7b97\u5bf9defer\u8981\u6267\u884c\u7684\u51fd\u6570\u7684\u53c2\u6570\u8fdb\u884c\u8ba1\u7b97\uff0c\u53ef\u4ee5\u8003\u8651\u5c06\u8981\u6267\u884c\u7684\u51fd\u6570\u653e\u5230\u95ed\u5305\u91cc\u9762\uff0c\u7136\u540e\u901a\u8fc7\u6307\u9488\u4f20\u9012\u53c2\u6570\u7ed9\u95ed\u5305\u5185\u51fd\u6570\uff08\u6216\u8005\u901a\u8fc7\u95ed\u5305\u6355\u83b7\u5916\u90e8\u53d8\u91cf\uff09\uff0c\u6765\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u3002
\u4f7f\u7528 panic
\u662fGo\u4e2d\u4e00\u79cd\u5904\u7406\u9519\u8bef\u7684\u65b9\u5f0f\uff0c\u4f46\u662f\u53ea\u80fd\u5728\u9047\u5230\u4e0d\u53ef\u6062\u590d\u7684\u9519\u8bef\u65f6\u4f7f\u7528\uff0c\u4f8b\u5982\uff1a\u901a\u77e5\u5f00\u53d1\u4eba\u5458\u4e00\u4e2a\u5f3a\u4f9d\u8d56\u7684\u6a21\u5757\u52a0\u8f7d\u5931\u8d25\u4e86\u3002
Wrapping\uff08\u5305\u88c5\uff09\u9519\u8bef\u5141\u8bb8\u60a8\u6807\u8bb0\u9519\u8bef\u3001\u63d0\u4f9b\u989d\u5916\u7684\u4e0a\u4e0b\u6587\u4fe1\u606f\u3002\u7136\u800c\uff0c\u5305\u88c5\u9519\u8bef\u4f1a\u521b\u5efa\u6f5c\u5728\u7684\u8026\u5408\uff0c\u56e0\u4e3a\u5b83\u4f7f\u5f97\u539f\u6765\u7684\u9519\u8bef\u5bf9\u8c03\u7528\u8005\u53ef\u89c1\u3002\u5982\u679c\u60a8\u60f3\u8981\u9632\u6b62\u8fd9\u79cd\u60c5\u51b5\uff0c\u8bf7\u4e0d\u8981\u4f7f\u7528\u5305\u88c5\u9519\u8bef\u7684\u65b9\u5f0f\u3002
"},{"location":"zh/#50","title":"\u4e0d\u6b63\u786e\u7684\u9519\u8bef\u7c7b\u578b\u6bd4\u8f83 (#50)","text":"\u5982\u679c\u4f60\u4f7f\u7528 Go 1.13 \u5f15\u5165\u7684\u7279\u6027 fmt.Errorf
+ %w
\u6765\u5305\u88c5\u4e00\u4e2a\u9519\u8bef\uff0c\u5f53\u8fdb\u884c\u9519\u8bef\u6bd4\u8f83\u65f6\uff0c\u5982\u679c\u60f3\u5224\u65ad\u8be5\u5305\u88c5\u540e\u7684\u9519\u8bef\u662f\u4e0d\u662f\u6307\u5b9a\u7684\u9519\u8bef\u7c7b\u578b\uff0c\u5c31\u9700\u8981\u4f7f\u7528 errors.As
\uff0c\u5982\u679c\u60f3\u5224\u65ad\u662f\u4e0d\u662f\u6307\u5b9a\u7684error\u5bf9\u8c61\u5c31\u9700\u8981\u7528 errors.Is
\u3002
\u89c1 #50.
\u4e3a\u4e86\u8868\u8fbe\u4e00\u4e2a\u9884\u671f\u5185\u7684\u9519\u8bef\uff0c\u8bf7\u4f7f\u7528\u9519\u8bef\u503c\u7684\u65b9\u5f0f\uff0c\u5e76\u901a\u8fc7 ==
\u6216\u8005 errors.Is
\u6765\u6bd4\u8f83\u3002\u800c\u5bf9\u4e8e\u610f\u5916\u9519\u8bef\uff0c\u5219\u5e94\u4f7f\u7528\u7279\u5b9a\u7684\u9519\u8bef\u7c7b\u578b\uff08\u53ef\u4ee5\u901a\u8fc7 errors.As
\u6765\u6bd4\u8f83\uff09\u3002
\u5927\u591a\u6570\u60c5\u51b5\u4e0b\uff0c\u9519\u8bef\u4ec5\u9700\u8981\u5904\u7406\u4e00\u6b21\u3002\u6253\u5370\u9519\u8bef\u65e5\u5fd7\u4e5f\u662f\u4e00\u79cd\u9519\u8bef\u5904\u7406\u3002\u56e0\u6b64\uff0c\u5f53\u51fd\u6570\u5185\u53d1\u751f\u9519\u8bef\u65f6\uff0c\u5e94\u8be5\u5728\u6253\u5370\u65e5\u5fd7\u548c\u8fd4\u56de\u9519\u8bef\u4e2d\u9009\u62e9\u5176\u4e2d\u4e00\u79cd\u3002\u5305\u88c5\u9519\u8bef\u4e5f\u53ef\u4ee5\u63d0\u4f9b\u95ee\u9898\u53d1\u751f\u7684\u989d\u5916\u4e0a\u4e0b\u6587\u4fe1\u606f\uff0c\u4e5f\u5305\u62ec\u4e86\u539f\u6765\u7684\u9519\u8bef\uff08\u53ef\u8003\u8651\u4ea4\u7ed9\u8c03\u7528\u65b9\u8d1f\u8d23\u6253\u65e5\u5fd7\uff09\u3002
"},{"location":"zh/#53","title":"\u4e0d\u5904\u7406\u9519\u8bef (#53)","text":"\u4e0d\u7ba1\u662f\u5728\u51fd\u6570\u8c03\u7528\u65f6\uff0c\u8fd8\u662f\u5728\u4e00\u4e2a defer
\u51fd\u6570\u6267\u884c\u65f6\uff0c\u5982\u679c\u60f3\u8981\u5ffd\u7565\u4e00\u4e2a\u9519\u8bef\uff0c\u5e94\u8be5\u663e\u793a\u5730\u901a\u8fc7 _
\u6765\u5ffd\u7565\uff08\u53ef\u6ce8\u660e\u5ffd\u7565\u7684\u539f\u56e0\uff09\u3002\u5426\u5219\uff0c\u5c06\u6765\u7684\u8bfb\u8005\u5c31\u4f1a\u611f\u89c9\u5230\u56f0\u60d1\uff0c\u5ffd\u7565\u8fd9\u4e2a\u9519\u8bef\u662f\u6709\u610f\u4e3a\u4e4b\u8fd8\u662f\u65e0\u610f\u4e2d\u6f0f\u6389\u4e86\u3002
defer
\u4e2d\u7684\u9519\u8bef (#54)","text":"\u5927\u591a\u6570\u60c5\u51b5\u4e0b\uff0c\u4f60\u4e0d\u5e94\u8be5\u5ffd\u7565 defer
\u51fd\u6570\u6267\u884c\u65f6\u8fd4\u56de\u7684\u9519\u8bef\uff0c\u6216\u8005\u663e\u793a\u5904\u7406\u5b83\uff0c\u6216\u8005\u5c06\u5b83\u4f20\u9012\u7ed9\u8c03\u7528\u65b9\u5904\u7406\uff0c\u53ef\u4ee5\u6839\u636e\u60c5\u666f\u8fdb\u884c\u9009\u62e9\u3002\u5982\u679c\u4f60\u786e\u5b9a\u8981\u5ffd\u7565\u8fd9\u4e2a\u9519\u8bef\uff0c\u8bf7\u663e\u793a\u4f7f\u7528 _
\u6765\u5ffd\u7565\u3002
\u7406\u89e3\u5e76\u53d1\uff08concurrency\uff09\u3001\u5e76\u884c\uff08parallelism\uff09\u4e4b\u95f4\u7684\u672c\u8d28\u533a\u522b\u662fGo\u5f00\u53d1\u4eba\u5458\u5fc5\u987b\u8981\u638c\u63e1\u7684\u3002\u5e76\u53d1\u662f\u5173\u4e8e\u7ed3\u6784\u8bbe\u8ba1\u4e0a\u7684\uff0c\u5e76\u884c\u662f\u5173\u4e8e\u5177\u4f53\u6267\u884c\u4e0a\u7684\u3002
"},{"location":"zh/#56","title":"\u8ba4\u4e3a\u5e76\u53d1\u603b\u662f\u66f4\u5feb (#56)","text":"\u8981\u6210\u4e3a\u4e00\u540d\u719f\u7ec3\u7684\u5f00\u53d1\u4eba\u5458\uff0c\u60a8\u5fc5\u987b\u610f\u8bc6\u5230\u5e76\u975e\u6240\u6709\u573a\u666f\u4e0b\u90fd\u662f\u5e76\u53d1\u7684\u65b9\u6848\u66f4\u5feb\u3002\u5bf9\u4e8e\u4efb\u52a1\u4e2d\u7684\u6700\u5c0f\u5de5\u4f5c\u8d1f\u8f7d\u90e8\u5206\uff0c\u5bf9\u5b83\u4eec\u8fdb\u884c\u5e76\u884c\u5316\u5904\u7406\u5e76\u4e0d\u4e00\u5b9a\u5c31\u6709\u660e\u663e\u6536\u76ca\u6216\u8005\u6bd4\u4e32\u884c\u5316\u65b9\u6848\u66f4\u5feb\u3002\u5bf9\u4e32\u884c\u5316\u3001\u5e76\u53d1\u65b9\u6848\u8fdb\u884cbenchmark\u6d4b\u8bd5\uff0c\u662f\u9a8c\u8bc1\u5047\u8bbe\u7684\u597d\u529e\u6cd5\u3002
"},{"location":"zh/#channelsmutexes-57","title":"\u4e0d\u6e05\u695a\u4f55\u65f6\u4f7f\u7528channels\u6216mutexes (#57)","text":"\u4e86\u89e3 goroutine \u4e4b\u95f4\u7684\u4ea4\u4e92\u4e5f\u53ef\u4ee5\u5728\u9009\u62e9\u4f7f\u7528channels\u6216mutexes\u65f6\u6709\u6240\u5e2e\u52a9\u3002\u4e00\u822c\u6765\u8bf4\uff0c\u5e76\u884c\u7684 goroutine \u9700\u8981\u540c\u6b65\uff0c\u56e0\u6b64\u9700\u8981\u4f7f\u7528mutexes\u3002\u76f8\u53cd\uff0c\u5e76\u53d1\u7684 goroutine \u901a\u5e38\u9700\u8981\u534f\u8c03\u548c\u7f16\u6392\uff0c\u56e0\u6b64\u9700\u8981\u4f7f\u7528channels\u3002
"},{"location":"zh/#vs-go-58","title":"\u4e0d\u660e\u767d\u7ade\u6001\u95ee\u9898 (\u6570\u636e\u7ade\u6001 vs. \u7ade\u6001\u6761\u4ef6 \u548c Go\u5185\u5b58\u6a21\u578b) (#58)","text":"\u638c\u63e1\u5e76\u53d1\u610f\u5473\u7740\u8981\u8ba4\u8bc6\u5230\u6570\u636e\u7ade\u4e89\uff08data races\uff09\u548c\u7ade\u6001\u6761\u4ef6\uff08race conditions\uff09\u662f\u4e24\u4e2a\u4e0d\u540c\u7684\u6982\u5ff5\u3002\u6570\u636e\u7ade\u4e89\uff0c\u6307\u7684\u662f\u6709\u591a\u4e2agoroutines\u540c\u65f6\u8bbf\u95ee\u76f8\u540c\u5185\u5b58\u533a\u57df\u65f6\uff0c\u6ca1\u6709\u5fc5\u8981\u7684\u540c\u6b65\u63a7\u5236\uff0c\u4e14\u5176\u4e2d\u81f3\u5c11\u6709\u4e00\u4e2agoroutine\u662f\u6267\u884c\u7684\u5199\u64cd\u4f5c\u3002\u540c\u65f6\u8981\u8ba4\u8bc6\u5230\uff0c\u6ca1\u6709\u53d1\u751f\u6570\u636e\u7ade\u4e89\u4e0d\u4ee3\u8868\u7a0b\u5e8f\u7684\u6267\u884c\u662f\u786e\u5b9a\u6027\u7684\u3001\u6ca1\u95ee\u9898\u7684\u3002\u5f53\u5728\u67d0\u4e2a\u7279\u5b9a\u7684\u64cd\u4f5c\u987a\u5e8f\u6216\u8005\u7279\u5b9a\u7684\u4e8b\u4ef6\u53d1\u751f\u987a\u5e8f\u4e0b\uff0c\u5982\u679c\u6700\u7ec8\u7684\u884c\u4e3a\u662f\u4e0d\u53ef\u63a7\u7684\uff0c\u8fd9\u5c31\u662f\u7ade\u6001\u6761\u4ef6\u3002
ps\uff1a\u6570\u636e\u7ade\u4e89\u662f\u7ade\u6001\u6761\u4ef6\u7684\u5b50\u96c6\uff0c\u7ade\u6001\u6761\u4ef6\u4e0d\u4ec5\u5c40\u9650\u4e8e\u8bbf\u5b58\u672a\u540c\u6b65\uff0c\u5b83\u53ef\u4ee5\u53d1\u751f\u5728\u66f4\u9ad8\u7684\u5c42\u9762\u3002go test -race
\u68c0\u6d4b\u7684\u662f\u6570\u636e\u7ade\u4e89\uff0c\u9700\u8981\u540c\u6b65\u6765\u89e3\u51b3\uff0c\u800c\u5f00\u53d1\u8005\u8fd8\u9700\u8981\u5173\u6ce8\u9762\u66f4\u5e7f\u7684\u7ade\u6001\u6761\u4ef6\uff0c\u5b83\u9700\u8981\u5bf9\u591a\u4e2agoroutines\u7684\u6267\u884c\u8fdb\u884c\u7f16\u6392\u3002
\u7406\u89e3 Go \u7684\u5185\u5b58\u6a21\u578b\u4ee5\u53ca\u6709\u5173\u987a\u5e8f\u548c\u540c\u6b65\u7684\u5e95\u5c42\u4fdd\u8bc1\u662f\u9632\u6b62\u53ef\u80fd\u7684\u6570\u636e\u7ade\u4e89\u548c\u7ade\u6001\u6761\u4ef6\u7684\u5173\u952e\u3002
"},{"location":"zh/#59","title":"\u4e0d\u7406\u89e3\u4e0d\u540c\u5de5\u4f5c\u8d1f\u8f7d\u7c7b\u578b\u5bf9\u5e76\u53d1\u7684\u5f71\u54cd (#59)","text":"\u5f53\u521b\u5efa\u4e00\u5b9a\u6570\u91cf\u7684goroutines\u662f\uff0c\u9700\u8981\u8003\u8651\u5de5\u4f5c\u8d1f\u8f7d\u7684\u7c7b\u578b\u3002\u5982\u679c\u5de5\u4f5c\u8d1f\u8f7d\u662fCPU\u5bc6\u96c6\u578b\u7684\uff0c\u90a3\u4e48goroutines\u6570\u91cf\u5e94\u8be5\u63a5\u8fd1\u4e8e GOMAXPROCS
\u7684\u503c\uff08\u8be5\u503c\u53d6\u51b3\u4e8e\u4e3b\u673a\u5904\u7406\u5668\u6838\u5fc3\u6570\uff09\u3002\u5982\u679c\u5de5\u4f5c\u8d1f\u8f7d\u662fIO\u5bc6\u96c6\u578b\u7684\uff0cgoroutines\u6570\u91cf\u5c31\u9700\u8981\u8003\u8651\u591a\u79cd\u56e0\u7d20\uff0c\u6bd4\u5982\u5916\u90e8\u7cfb\u7edf\uff08\u8003\u8651\u8bf7\u6c42\u3001\u54cd\u5e94\u901f\u7387\uff09\u3002
Go \u7684\u4e0a\u4e0b\u6587\uff08context\uff09\u4e5f\u662f Go \u5e76\u53d1\u7f16\u7a0b\u7684\u57fa\u77f3\u4e4b\u4e00\u3002\u4e0a\u4e0b\u6587\u5141\u8bb8\u60a8\u643a\u5e26\u622a\u6b62\u65f6\u95f4\u3001\u53d6\u6d88\u4fe1\u53f7\u548c\u952e\u503c\u5217\u8868\u3002
"},{"location":"zh/#_8","title":"\u5e76\u53d1\u7f16\u7a0b: \u5b9e\u8df5","text":""},{"location":"zh/#context-61","title":"\u4f20\u9012\u4e0d\u5408\u9002\u7684context (#61)","text":"\u5f53\u6211\u4eec\u4f20\u9012\u4e86\u4e00\u4e2acontext\uff0c\u6211\u4eec\u9700\u8981\u77e5\u9053\u8fd9\u4e2acontext\u4ec0\u4e48\u65f6\u5019\u53ef\u4ee5\u88ab\u53d6\u6d88\uff0c\u8fd9\u70b9\u5f88\u91cd\u8981\uff0c\u4f8b\u5982\uff1a\u4e00\u4e2aHTTP\u8bf7\u6c42\u5904\u7406\u5668\u5728\u53d1\u9001\u5b8c\u54cd\u5e94\u540e\u53d6\u6d88context\u3002
ps: \u5b9e\u9645\u4e0acontext\u8868\u8fbe\u7684\u662f\u4e00\u4e2a\u52a8\u4f5c\u53ef\u4ee5\u6301\u7eed\u591a\u4e45\u4e4b\u540e\u88ab\u505c\u6b62\u3002
"},{"location":"zh/#goroutine-62","title":"\u542f\u52a8\u4e86\u4e00\u4e2agoroutine\u4f46\u662f\u4e0d\u77e5\u9053\u5b83\u4f55\u65f6\u4f1a\u505c\u6b62 (#62)","text":"\u907f\u514dgoroutine\u6cc4\u6f0f\uff0c\u8981\u6709\u8fd9\u79cd\u610f\u8bc6\uff0c\u5f53\u521b\u5efa\u5e76\u542f\u52a8\u4e00\u4e2agoroutine\u7684\u65f6\u5019\uff0c\u5e94\u8be5\u6709\u5bf9\u5e94\u7684\u8bbe\u8ba1\u8ba9\u5b83\u80fd\u6b63\u5e38\u9000\u51fa\u3002
"},{"location":"zh/#goroutines-63","title":"\u4e0d\u6ce8\u610f\u5904\u7406 goroutines \u548c \u5faa\u73af\u4e2d\u7684\u8fed\u4ee3\u53d8\u91cf (#63)","text":"\u4e3a\u4e86\u907f\u514dgoroutines\u548c\u5faa\u73af\u4e2d\u7684\u8fed\u4ee3\u53d8\u91cf\u95ee\u9898\uff0c\u53ef\u4ee5\u8003\u8651\u521b\u5efa\u5c40\u90e8\u53d8\u91cf\u5e76\u5c06\u8fed\u4ee3\u53d8\u91cf\u8d4b\u503c\u7ed9\u5c40\u90e8\u53d8\u91cf\uff0c\u6216\u8005goroutine\u8c03\u7528\u5e26\u53c2\u6570\u7684\u51fd\u6570\uff0c\u5c06\u8fed\u4ee3\u53d8\u91cf\u503c\u4f5c\u4e3a\u53c2\u6570\u503c\u4f20\u5165\uff0c\u6765\u4ee3\u66ffgoroutine\u8c03\u7528\u95ed\u5305\u3002
"},{"location":"zh/#select-channels-64","title":"\u4f7f\u7528select + channels \u65f6\u8bef\u4ee5\u4e3a\u5206\u652f\u9009\u62e9\u987a\u5e8f\u662f\u786e\u5b9a\u7684 (#64)","text":"\u8981\u660e\u767d\uff0cselect
\u591a\u4e2achannels\u65f6\uff0c\u5982\u679c\u591a\u4e2achannels\u4e0a\u7684\u64cd\u4f5c\u90fd\u5c31\u7eea\uff0c\u90a3\u4e48\u4f1a\u968f\u673a\u9009\u62e9\u4e00\u4e2a case
\u5206\u652f\u6765\u6267\u884c\uff0c\u56e0\u6b64\u8981\u907f\u514d\u6709\u5206\u652f\u9009\u62e9\u987a\u5e8f\u662f\u4ece\u4e0a\u5230\u4e0b\u7684\u8fd9\u79cd\u9519\u8bef\u9884\u8bbe\uff0c\u8fd9\u53ef\u80fd\u4f1a\u5bfc\u81f4\u8bbe\u8ba1\u4e0a\u7684bug\u3002
\u53d1\u9001\u901a\u77e5\u65f6\u4f7f\u7528 chan struct{}
\u7c7b\u578b\u3002
ps: \u5148\u660e\u767d\u4ec0\u4e48\u662f\u901a\u77e5channels\uff0c\u4e00\u4e2a\u901a\u77e5channels\u6307\u7684\u662f\u53ea\u662f\u7528\u6765\u505a\u901a\u77e5\uff0c\u800c\u5176\u4e2d\u4f20\u9012\u7684\u6570\u636e\u6ca1\u6709\u610f\u4e49\uff0c\u6216\u8005\u7406\u89e3\u6210\u4e0d\u4f20\u9012\u6570\u636e\u7684channels\uff0c\u8fd9\u79cd\u79f0\u4e3a\u901a\u77e5channels\u3002\u5176\u4e2d\u4f20\u9012\u7684\u6570\u636e\u7684\u7c7b\u578bstruct{}\u66f4\u5408\u9002\u3002
"},{"location":"zh/#nil-channels-66","title":"\u4e0d\u4f7f\u7528 nil channels (#66)","text":"\u4f7f\u7528 nil channels \u5e94\u8be5\u662f\u5e76\u53d1\u5904\u7406\u65b9\u5f0f\u4e2d\u7684\u4e00\u90e8\u5206\uff0c\u4f8b\u5982\uff0c\u5b83\u80fd\u591f\u5e2e\u52a9\u7981\u7528 select
\u8bed\u53e5\u4e2d\u7684\u7279\u5b9a\u7684\u5206\u652f\u3002
\u6839\u636e\u6307\u5b9a\u7684\u573a\u666f\u4ed4\u7ec6\u8bc4\u4f30\u5e94\u8be5\u4f7f\u7528\u54ea\u4e00\u79cd channel \u7c7b\u578b\uff08\u5e26\u7f13\u51b2\u7684\uff0c\u4e0d\u5e26\u7f13\u51b2\u7684\uff09\u3002\u53ea\u6709\u4e0d\u5e26\u7f13\u51b2\u7684 channels \u53ef\u4ee5\u63d0\u4f9b\u5f3a\u540c\u6b65\u4fdd\u8bc1\u3002
\u4f7f\u7528\u5e26\u7f13\u51b2\u7684 channels \u65f6\u5982\u679c\u4e0d\u786e\u5b9a size \u8be5\u5982\u4f55\u8bbe\u7f6e\uff0c\u53ef\u4ee5\u5148\u8bbe\u4e3a1\uff0c\u5982\u679c\u6709\u5408\u7406\u7684\u7406\u7531\u518d\u53bb\u6307\u5b9a channels size\u3002
ps: \u6839\u636edisruptor\u8fd9\u4e2a\u9ad8\u6027\u80fd\u5185\u5b58\u6d88\u606f\u961f\u5217\u7684\u5b9e\u8df5\uff0c\u5728\u67d0\u79cd\u8bfb\u5199pacing\u4e0b\uff0c\u961f\u5217\u8981\u4e48\u6ee1\u8981\u4e48\u7a7a\uff0c\u4e0d\u5927\u53ef\u80fd\u5904\u4e8e\u67d0\u79cd\u4ecb\u4e8e\u4e2d\u95f4\u7684\u7a33\u6001\u3002
"},{"location":"zh/#etcd-68","title":"\u5fd8\u8bb0\u4e86\u5b57\u7b26\u4e32\u683c\u5f0f\u5316\u53ef\u80fd\u5e26\u6765\u7684\u526f\u4f5c\u7528\uff08\u4f8b\u5982 etcd \u6570\u636e\u7ade\u4e89\u548c\u6b7b\u9501\uff09(#68)","text":"\u610f\u8bc6\u5230\u5b57\u7b26\u4e32\u683c\u5f0f\u5316\u53ef\u80fd\u4f1a\u5bfc\u81f4\u8c03\u7528\u73b0\u6709\u51fd\u6570\uff0c\u8fd9\u610f\u5473\u7740\u9700\u8981\u6ce8\u610f\u53ef\u80fd\u7684\u6b7b\u9501\u548c\u5176\u4ed6\u6570\u636e\u7ade\u4e89\u95ee\u9898\u3002
ps: \u6838\u5fc3\u662f\u8981\u5173\u6ce8 fmt.Sprintf
+ %v
\u8fdb\u884c\u5b57\u7b26\u4e32\u683c\u5f0f\u5316\u65f6 %v
\u5177\u4f53\u5230\u4e0d\u540c\u7684\u7c7b\u578b\u503c\u65f6\uff0c\u5b9e\u9645\u4e0a\u6267\u884c\u7684\u64cd\u4f5c\u662f\u4ec0\u4e48\u3002\u6bd4\u5982 %v
\u8fd9\u4e2aplaceholder\u5bf9\u5e94\u7684\u503c\u65f6\u4e00\u4e2a context.Context
\uff0c\u90a3\u4e48\u4f1a\u5c31\u904d\u5386\u5176\u901a\u8fc7 context.WithValue
\u9644\u52a0\u5728\u5176\u4e2d\u7684 values\uff0c\u8fd9\u4e2a\u8fc7\u7a0b\u53ef\u80fd\u6d89\u53ca\u5230\u6570\u636e\u7ade\u4e89\u95ee\u9898\u3002\u4e66\u4e2d\u63d0\u53ca\u7684\u53e6\u4e00\u4e2a\u5bfc\u81f4\u6b7b\u9501\u7684\u6848\u4f8b\u672c\u8d28\u4e0a\u4e5f\u662f\u4e00\u6837\u7684\u95ee\u9898\uff0c\u53ea\u4e0d\u8fc7\u53c8\u989d\u5916\u7275\u626f\u5230\u4e86 sync.RWMutex
\u4e0d\u53ef\u91cd\u5165\u7684\u95ee\u9898\u3002
\u8c03\u7528 append
\u4e0d\u603b\u662f\u6ca1\u6709\u6570\u636e\u7ade\u4e89\u7684\uff0c\u56e0\u6b64\u4e0d\u8981\u5728\u4e00\u4e2a\u5171\u4eab\u7684 slice
\u4e0a\u5e76\u53d1\u5730\u6267\u884c append
\u3002
\u8bf7\u8bb0\u4f4f slices \u548c maps \u5f15\u7528\u7c7b\u578b\uff0c\u6709\u52a9\u4e8e\u907f\u514d\u5e38\u89c1\u7684\u6570\u636e\u7ade\u4e89\u95ee\u9898\u3002
ps: \u8fd9\u91cc\u5b9e\u9645\u662f\u56e0\u4e3a\u9519\u8bef\u7406\u89e3\u4e86 slices \u548c maps\uff0c\u5bfc\u81f4\u5199\u51fa\u4e86\u9519\u8bef\u7684\u62f7\u8d1d slices \u548c maps \u7684\u4ee3\u7801\uff0c\u8fdb\u800c\u5bfc\u81f4\u9501\u4fdd\u62a4\u65e0\u6548\u3001\u51fa\u73b0\u6570\u636e\u7ade\u4e89\u95ee\u9898\u3002
"},{"location":"zh/#syncwaitgroup-71","title":"\u8bef\u7528sync.WaitGroup
(#71)","text":"\u6b63\u786e\u5730\u4f7f\u7528 sync.WaitGroup
\u9700\u8981\u5728\u542f\u52a8 goroutines \u4e4b\u524d\u5148\u8c03\u7528 Add
\u65b9\u6cd5\u3002
sync.Cond
(#72)","text":"\u4f60\u53ef\u4ee5\u4f7f\u7528 sync.Cond
\u5411\u591a\u4e2a goroutines \u53d1\u9001\u91cd\u590d\u7684\u901a\u77e5\u3002
errgroup
(#73)","text":"\u4f60\u53ef\u4ee5\u4f7f\u7528 errgroup
\u5305\u6765\u540c\u6b65\u4e00\u7ec4 goroutines \u5e76\u5904\u7406\u9519\u8bef\u548c\u4e0a\u4e0b\u6587\u3002
sync
\u4e0b\u7684\u7c7b\u578b (#74)","text":"sync
\u5305\u4e0b\u7684\u7c7b\u578b\u4e0d\u5e94\u8be5\u88ab\u62f7\u8d1d\u3002
\u6ce8\u610f\u6709\u4e9b\u51fd\u6570\u63a5\u6536\u4e00\u4e2a time.Duration
\u7c7b\u578b\u7684\u53c2\u6570\u65f6\uff0c\u5c3d\u7ba1\u76f4\u63a5\u4f20\u9012\u4e00\u4e2a\u6574\u6570\u662f\u53ef\u4ee5\u7684\uff0c\u4f46\u6700\u597d\u8fd8\u662f\u4f7f\u7528 time API \u4e2d\u7684\u65b9\u6cd5\u6765\u4f20\u9012 duration\uff0c\u4ee5\u907f\u514d\u53ef\u80fd\u9020\u6210\u7684\u56f0\u60d1\u3001bug\u3002
ps: \u91cd\u70b9\u662f\u6ce8\u610f time.Duration \u5b9a\u4e49\u7684\u662f nanoseconds \u6570\u3002
"},{"location":"zh/#timeafter-76","title":"time.After
\u548c\u5185\u5b58\u6cc4\u6f0f (#76)","text":"\u907f\u514d\u5728\u91cd\u590d\u6267\u884c\u5f88\u591a\u6b21\u7684\u51fd\u6570 \uff08\u5982\u5faa\u73af\u4e2d\u6216HTTP\u5904\u7406\u51fd\u6570\uff09\u4e2d\u8c03\u7528 time.After
\uff0c\u8fd9\u53ef\u4ee5\u907f\u514d\u5185\u5b58\u5cf0\u503c\u6d88\u8017\u3002\u7531 time.After
\u521b\u5efa\u7684\u8d44\u6e90\u4ec5\u5728\u8ba1\u65f6\u5668\u8d85\u65f6\u624d\u4f1a\u88ab\u91ca\u653e\u3002
\u8981\u5f53\u5fc3\u5728Go\u7ed3\u6784\u4f53\u4e2d\u5d4c\u5165\u5b57\u6bb5\uff0c\u8fd9\u6837\u505a\u53ef\u80fd\u4f1a\u5bfc\u81f4\u8bf8\u5982\u5d4c\u5165\u7684 time.Time
\u5b57\u6bb5\u5b9e\u73b0 json.Marshaler
\u63a5\u53e3\uff0c\u4ece\u800c\u8986\u76d6\u9ed8\u8ba4\u7684json\u5e8f\u5217\u3002
\u5f53\u5bf9\u4e24\u4e2a time.Time
\u7c7b\u578b\u503c\u8fdb\u884c\u6bd4\u8f83\u65f6\uff0c\u9700\u8981\u8bb0\u4f4f time.Time
\u5305\u542b\u4e86\u4e00\u4e2a\u5899\u4e0a\u65f6\u949f\uff08wall clock\uff09\u548c\u4e00\u4e2a\u5355\u8c03\u65f6\u949f \uff08monotonic clock\uff09\uff0c\u800c\u4f7f\u7528 ==
\u8fd0\u7b97\u7b26\u8fdb\u884c\u6bd4\u8f83\u65f6\u4f1a\u540c\u65f6\u6bd4\u8f83\u8fd9\u4e24\u4e2a\u3002
any
\u5f53\u63d0\u4f9b\u4e00\u4e2amap\u7528\u6765unmarshal JSON\u6570\u636e\u65f6\uff0c\u4e3a\u4e86\u907f\u514d\u4e0d\u786e\u5b9a\u7684value\u7ed3\u6784\u6211\u4eec\u4f1a\u4f7f\u7528 any
\u6765\u4f5c\u4e3avalue\u7684\u7c7b\u578b\u800c\u4e0d\u662f\u5b9a\u4e49\u4e00\u4e2astruct\uff0c\u8fd9\u79cd\u60c5\u51b5\u4e0b\u9700\u8981\u8bb0\u5f97\u6570\u503c\u9ed8\u8ba4\u4f1a\u88ab\u8f6c\u6362\u4e3a float64
\u3002
sql.Open
\u5e76\u6ca1\u6709\u4e0edb\u670d\u52a1\u5668\u5efa\u7acb\u5b9e\u9645\u8fde\u63a5\u9700\u8981\u8c03\u7528 Ping
\u6216\u8005 PingContext
\u65b9\u6cd5\u6765\u6d4b\u8bd5\u914d\u7f6e\u5e76\u786e\u4fdd\u6570\u636e\u5e93\u662f\u53ef\u8fbe\u7684\u3002
\u4f5c\u4e3a\u751f\u4ea7\u7ea7\u522b\u7684\u5e94\u7528\uff0c\u8bbf\u95ee\u6570\u636e\u5e93\u65f6\u5e94\u8be5\u5173\u6ce8\u914d\u7f6e\u6570\u636e\u5e93\u8fde\u63a5\u6c60\u53c2\u6570\u3002
\u4f7f\u7528 SQL prepared \u8bed\u53e5\u80fd\u591f\u8ba9\u67e5\u8be2\u66f4\u52a0\u9ad8\u6548\u548c\u5b89\u5168\u3002
\u4f7f\u7528 sql.NullXXX
\u7c7b\u578b\u5904\u7406\u8868\u4e2d\u7684\u53ef\u7a7a\u5217\u3002
\u8c03\u7528 sql.Rows
\u7684 Err
\u65b9\u6cd5\u6765\u786e\u4fdd\u5728\u51c6\u5907\u4e0b\u4e00\u4e2a\u884c\u65f6\u6ca1\u6709\u9057\u6f0f\u9519\u8bef\u3002
sql.Rows
\u548c os.File
) (#79)","text":"\u6700\u7ec8\u8981\u6ce8\u610f\u5173\u95ed\u6240\u6709\u5b9e\u73b0 io.Closer
\u63a5\u53e3\u7684\u7ed3\u6784\u4f53,\u4ee5\u907f\u514d\u53ef\u80fd\u7684\u6cc4\u6f0f\u3002
\u4e3a\u4e86\u907f\u514d\u5728HTTP\u5904\u7406\u51fd\u6570\u4e2d\u51fa\u73b0\u67d0\u4e9b\u610f\u5916\u7684\u95ee\u9898\uff0c\u5982\u679c\u60f3\u5728\u53d1\u751f http.Error
\u540e\u8ba9HTTP\u5904\u7406\u51fd\u6570\u505c\u6b62\uff0c\u90a3\u4e48\u5c31\u4e0d\u8981\u5fd8\u8bb0\u4f7f\u7528return
\u8bed\u53e5\u6765\u963b\u6b62\u540e\u7eed\u4ee3\u7801\u7684\u6267\u884c\u3002
\u5bf9\u4e8e\u751f\u4ea7\u7ea7\u522b\u7684\u5e94\u7528\uff0c\u4e0d\u8981\u4f7f\u7528\u9ed8\u8ba4\u7684HTTP client\u548cserver\u5b9e\u73b0\u3002\u8fd9\u4e9b\u5b9e\u73b0\u7f3a\u5c11\u8d85\u65f6\u548c\u751f\u4ea7\u73af\u5883\u4e2d\u5e94\u8be5\u5f3a\u5236\u4f7f\u7528\u7684\u884c\u4e3a\u3002
"},{"location":"zh/#_10","title":"\u6d4b\u8bd5","text":""},{"location":"zh/#build-tags-82","title":"\u4e0d\u5bf9\u6d4b\u8bd5\u8fdb\u884c\u5206\u7c7b \uff08build tags, \u73af\u5883\u53d8\u91cf\uff0c\u77ed\u6a21\u5f0f\uff09(#82)","text":"\u5bf9\u6d4b\u8bd5\u8fdb\u884c\u5fc5\u8981\u7684\u5206\u7c7b\uff0c\u53ef\u4ee5\u501f\u52a9 build tags\u3001\u73af\u5883\u53d8\u91cf\u4ee5\u53ca\u77ed\u6a21\u5f0f\uff0c\u6765\u4f7f\u5f97\u6d4b\u8bd5\u8fc7\u7a0b\u66f4\u52a0\u9ad8\u6548\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528 build tags \u6216\u73af\u5883\u53d8\u91cf\u6765\u521b\u5efa\u6d4b\u8bd5\u7c7b\u522b\uff08\u4f8b\u5982\u5355\u5143\u6d4b\u8bd5\u4e0e\u96c6\u6210\u6d4b\u8bd5\uff09\uff0c\u5e76\u533a\u5206\u77ed\u6d4b\u8bd5\u4e0e\u957f\u65f6\u95f4\u6d4b\u8bd5\uff0c\u6765\u51b3\u5b9a\u6267\u884c\u54ea\u79cd\u7c7b\u578b\u7684\u3002
ps: \u4e86\u89e3\u4e0bgo build tags\uff0c\u4ee5\u53ca go test -short
\u3002
\u6253\u5f00 -race
\u5f00\u5173\u5728\u7f16\u5199\u5e76\u53d1\u5e94\u7528\u65f6\u975e\u5e38\u91cd\u8981\u3002\u8fd9\u80fd\u5e2e\u52a9\u4f60\u6355\u83b7\u53ef\u80fd\u7684\u6570\u636e\u7ade\u4e89,\u4ece\u800c\u907f\u514d\u8f6f\u4ef6bug\u3002
\u6253\u5f00\u5f00\u5173 -parallel
\u6709\u52a9\u4e8e\u52a0\u901f\u6d4b\u8bd5\u7684\u6267\u884c\uff0c\u7279\u522b\u662f\u6d4b\u8bd5\u4e2d\u5305\u542b\u4e00\u4e9b\u9700\u8981\u957f\u671f\u8fd0\u884c\u7684\u7528\u4f8b\u7684\u65f6\u5019\u3002
\u6253\u5f00\u5f00\u5173 -shuffle
\u80fd\u591f\u6253\u4e71\u6d4b\u8bd5\u7528\u4f8b\u6267\u884c\u7684\u987a\u5e8f\uff0c\u907f\u514d\u4e00\u4e2a\u6d4b\u8bd5\u4f9d\u8d56\u4e8e\u67d0\u4e9b\u4e0d\u7b26\u5408\u771f\u5b9e\u60c5\u51b5\u7684\u9884\u8bbe\uff0c\u6709\u52a9\u4e8e\u53ca\u65e9\u66b4\u6f0fbug\u3002
\u8868\u9a71\u52a8\u7684\u6d4b\u8bd5\u662f\u4e00\u79cd\u6709\u6548\u7684\u65b9\u5f0f,\u53ef\u4ee5\u5c06\u4e00\u7ec4\u76f8\u4f3c\u7684\u6d4b\u8bd5\u5206\u7ec4\u5728\u4e00\u8d77,\u4ee5\u907f\u514d\u4ee3\u7801\u91cd\u590d\u548c\u4f7f\u672a\u6765\u7684\u66f4\u65b0\u66f4\u5bb9\u6613\u5904\u7406\u3002
"},{"location":"zh/#sleep-86","title":"\u5728\u5355\u5143\u6d4b\u8bd5\u4e2d\u6267\u884csleep\u64cd\u4f5c (#86)","text":"\u4f7f\u7528\u540c\u6b65\u7684\u65b9\u5f0f\u3001\u907f\u514dsleep\uff0c\u6765\u5c3d\u91cf\u51cf\u5c11\u6d4b\u8bd5\u7684\u4e0d\u7a33\u5b9a\u6027\u548c\u63d0\u9ad8\u9c81\u68d2\u6027\u3002\u5982\u679c\u65e0\u6cd5\u4f7f\u7528\u540c\u6b65\u624b\u6bb5,\u53ef\u4ee5\u8003\u8651\u91cd\u8bd5\u7684\u65b9\u5f0f\u3002
"},{"location":"zh/#time-api-87","title":"\u6ca1\u6709\u9ad8\u6548\u5730\u5904\u7406 time API (#87)","text":"\u7406\u89e3\u5982\u4f55\u5904\u7406\u4f7f\u7528 time API \u7684\u51fd\u6570\uff0c\u662f\u4f7f\u6d4b\u8bd5\u66f4\u52a0\u7a33\u5b9a\u7684\u53e6\u4e00\u79cd\u65b9\u5f0f\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528\u6807\u51c6\u6280\u672f\uff0c\u4f8b\u5982\u5c06\u65f6\u95f4\u4f5c\u4e3a\u9690\u85cf\u4f9d\u8d56\u9879\u7684\u4e00\u90e8\u5206\u6765\u5904\u7406\uff0c\u6216\u8005\u8981\u6c42\u5ba2\u6237\u7aef\u63d0\u4f9b\u65f6\u95f4\u3002
"},{"location":"zh/#httptest-iotest-88","title":"\u4e0d\u4f7f\u7528\u6d4b\u8bd5\u76f8\u5173\u7684\u5de5\u5177\u5305 (httptest
\u548c iotest
) (#88)","text":"\u8fd9\u4e2a httptest
\u5305\u5bf9\u5904\u7406HTTP\u5e94\u7528\u7a0b\u5e8f\u5f88\u6709\u5e2e\u52a9\u3002\u5b83\u63d0\u4f9b\u4e86\u4e00\u7ec4\u5b9e\u7528\u7a0b\u5e8f\u6765\u6d4b\u8bd5\u5ba2\u6237\u7aef\u548c\u670d\u52a1\u5668\u3002
\u8fd9\u4e2a iotest
\u5305\u6709\u52a9\u4e8e\u7f16\u5199 io.Reader \u5e76\u6d4b\u8bd5\u5e94\u7528\u7a0b\u5e8f\u662f\u5426\u80fd\u591f\u5bb9\u5fcd\u9519\u8bef\u3002
\u4f7f\u7528 time \u65b9\u6cd5\u6765\u4fdd\u6301\u57fa\u51c6\u6d4b\u8bd5\u7684\u51c6\u786e\u6027\u3002
\u589e\u52a0 benchtime
\u6216\u8005\u4f7f\u7528 benchstat
\u7b49\u5de5\u5177\u53ef\u4ee5\u6709\u52a9\u4e8e\u5fae\u57fa\u51c6\u6d4b\u8bd5\u3002
\u5c0f\u5fc3\u5fae\u57fa\u51c6\u6d4b\u8bd5\u7684\u7ed3\u679c,\u5982\u679c\u6700\u7ec8\u8fd0\u884c\u5e94\u7528\u7a0b\u5e8f\u7684\u7cfb\u7edf\u4e0e\u8fd0\u884c\u5fae\u57fa\u51c6\u6d4b\u8bd5\u7684\u7cfb\u7edf\u4e0d\u540c\u3002
\u786e\u4fdd\u6d4b\u8bd5\u51fd\u6570\u662f\u5426\u4f1a\u4ea7\u751f\u4e00\u4e9b\u526f\u4f5c\u7528\uff0c\u9632\u6b62\u7f16\u8bd1\u5668\u4f18\u5316\u6b3a\u9a97\u4f60\u5f97\u5230\u7684\u57fa\u51c6\u6d4b\u8bd5\u7ed3\u679c\u3002
\u4e3a\u4e86\u907f\u514d\u88ab\u89c2\u5bdf\u8005\u6548\u5e94\u6b3a\u9a97,\u5f3a\u5236\u91cd\u65b0\u521b\u5efaCPU\u5bc6\u96c6\u578b\u51fd\u6570\u4f7f\u7528\u7684\u6570\u636e\u3002
"},{"location":"zh/#go-test-90","title":"\u6ca1\u6709\u53bb\u63a2\u7d22go test\u6240\u6709\u7684\u7279\u6027 (#90)","text":"\u4f7f\u7528 -coverprofile
\u53c2\u6570\u53ef\u4ee5\u5feb\u901f\u67e5\u770b\u4ee3\u7801\u7684\u6d4b\u8bd5\u8986\u76d6\u60c5\u51b5\uff0c\u65b9\u4fbf\u5feb\u901f\u67e5\u770b\u54ea\u4e2a\u90e8\u5206\u9700\u8981\u66f4\u591a\u7684\u5173\u6ce8\u3002
\u5355\u5143\u6d4b\u8bd5\u7ec4\u7ec7\u5230\u4e00\u4e2a\u72ec\u7acb\u7684\u5305\u4e2d\uff0c\u5bf9\u4e8e\u5bf9\u5916\u5c42\u66b4\u6f0f\u7684\u63a5\u53e3\uff0c\u9700\u8981\u5199\u4e00\u4e9b\u6d4b\u8bd5\u7528\u4f8b\u3002\u6d4b\u8bd5\u5e94\u8be5\u5173\u6ce8\u516c\u5f00\u7684\u884c\u4e3a\uff0c\u800c\u975e\u5185\u90e8\u5b9e\u73b0\u7ec6\u8282\u3002
\u5904\u7406\u9519\u8bef\u65f6,\u4f7f\u7528 *testing.T
\u53d8\u91cf\u800c\u4e0d\u662f\u7ecf\u5178\u7684 if err != nil
\u53ef\u4ee5\u8ba9\u4ee3\u7801\u66f4\u52a0\u7b80\u6d01\u6613\u8bfb\u3002
\u4f60\u53ef\u4ee5\u4f7f\u7528setup\u548cteardown\u51fd\u6570\u6765\u914d\u7f6e\u4e00\u4e2a\u590d\u6742\u7684\u73af\u5883\uff0c\u6bd4\u5982\u5728\u96c6\u6210\u6d4b\u8bd5\u7684\u60c5\u51b5\u4e0b\u3002
"},{"location":"zh/#_11","title":"\u4e0d\u4f7f\u7528\u6a21\u7cca\u6d4b\u8bd5 (\u793e\u533a\u53cd\u9988\u9519\u8bef)","text":"\u6a21\u7cca\u6d4b\u8bd5\u662f\u4e00\u79cd\u9ad8\u6548\u7684\u7b56\u7565\uff0c\u4f7f\u7528\u5b83\u80fd\u68c0\u6d4b\u51fa\u968f\u673a\u3001\u610f\u6599\u5916\u7684\u548c\u4e00\u4e9b\u6076\u610f\u7684\u6570\u636e\u8f93\u5165\uff0c\u6765\u5b8c\u6210\u4e00\u4e9b\u590d\u6742\u7684\u64cd\u4f5c\u3002
\u89c1: @jeromedoucet
"},{"location":"zh/#_12","title":"\u4f18\u5316\u6280\u672f","text":""},{"location":"zh/#cpu-cache-91","title":"\u4e0d\u7406\u89e3CPU cache (#91)","text":"\u7406\u89e3CPU\u7f13\u5b58\u7684\u4f7f\u7528\u5bf9\u4e8e\u4f18\u5316CPU\u5bc6\u96c6\u578b\u5e94\u7528\u5f88\u91cd\u8981\uff0c\u56e0\u4e3aL1\u7f13\u5b58\u6bd4\u4e3b\u5b58\u5feb50\u5230100\u500d\u3002
\u610f\u8bc6\u5230 cache line \u6982\u5ff5\u5bf9\u4e8e\u7406\u89e3\u5982\u4f55\u5728\u6570\u636e\u5bc6\u96c6\u578b\u5e94\u7528\u4e2d\u7ec4\u7ec7\u6570\u636e\u975e\u5e38\u5173\u952e\u3002CPU \u5e76\u4e0d\u662f\u4e00\u4e2a\u4e00\u4e2a\u5b57\u6765\u83b7\u53d6\u5185\u5b58\u3002\u76f8\u53cd\uff0c\u5b83\u901a\u5e38\u590d\u5236\u4e00\u4e2a 64\u5b57\u8282\u957f\u5ea6\u7684 cache line\u3002\u4e3a\u4e86\u83b7\u5f97\u6bcf\u4e2a cache line \u7684\u6700\u5927\u6548\u7528\uff0c\u9700\u8981\u5b9e\u65bd\u7a7a\u95f4\u5c40\u90e8\u6027\u3002
\u4e00\u7cfb\u5217struct\u5143\u7d20\u6784\u6210\u7684slice vs. \u591a\u4e2aslice\u5b57\u6bb5\u6784\u6210\u7684struct
\u6982\u7387\u6027\u7684\u95ee\u9898
\u63d0\u9ad8CPU\u6267\u884c\u4ee3\u7801\u65f6\u7684\u53ef\u9884\u6d4b\u6027\uff0c\u4e5f\u662f\u4f18\u5316\u67d0\u4e9b\u51fd\u6570\u7684\u4e00\u4e2a\u6709\u6548\u65b9\u6cd5\u3002\u6bd4\u5982\uff0c\u56fa\u5b9a\u6b65\u957f\u6216\u8fde\u7eed\u8bbf\u95ee\u5bf9CPU\u6765\u8bf4\u662f\u53ef\u9884\u6d4b\u7684\uff0c\u4f46\u975e\u8fde\u7eed\u8bbf\u95ee\uff08\u4f8b\u5982\u94fe\u8868\uff09\u5c31\u662f\u4e0d\u53ef\u9884\u6d4b\u7684\u3002
\u8981\u6ce8\u610f\u73b0\u4ee3\u7f13\u5b58\u662f\u5206\u533a\u7684\uff08set associative placement\uff0c\u7ec4\u76f8\u8fde\u6620\u5c04\uff09\uff0c\u8981\u6ce8\u610f\u907f\u514d\u4f7f\u7528 critical stride
\uff0c\u8fd9\u79cd\u6b65\u957f\u60c5\u51b5\u4e0b\u53ea\u80fd\u5229\u7528 cache \u7684\u4e00\u5c0f\u90e8\u5206\u3002
critical stride\uff0c\u8fd9\u79cd\u7c7b\u578b\u7684\u6b65\u957f\uff0c\u6307\u7684\u662f\u5185\u5b58\u8bbf\u95ee\u7684\u6b65\u957f\u521a\u597d\u7b49\u4e8e cache \u5927\u5c0f\u3002\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u53ea\u6709\u5c11\u90e8\u5206 cacheline \u88ab\u5229\u7528\u3002
"},{"location":"zh/#false-sharing-92","title":"\u5199\u7684\u5e76\u53d1\u5904\u7406\u903b\u8f91\u4f1a\u5bfc\u81f4false sharing (#92)","text":"\u4e86\u89e3 CPU \u7f13\u5b58\u7684\u8f83\u4f4e\u5c42\u7684 L1\u3001L2 cache \u4e0d\u4f1a\u5728\u6240\u6709\u6838\u95f4\u5171\u4eab\uff0c\u7f16\u5199\u5e76\u53d1\u5904\u7406\u903b\u8f91\u65f6\u80fd\u907f\u514d\u5199\u51fa\u4e00\u4e9b\u964d\u4f4e\u6027\u80fd\u7684\u95ee\u9898\uff0c\u6bd4\u5982\u4f2a\u5171\u4eab\uff08false sharing\uff09\u3002\u5185\u5b58\u5171\u4eab\u53ea\u662f\u4e00\u79cd\u5047\u8c61\u3002
"},{"location":"zh/#93","title":"\u6ca1\u6709\u8003\u8651\u6307\u4ee4\u7ea7\u7684\u5e76\u884c (#93)","text":"\u4f7f\u7528\u6307\u4ee4\u7ea7\u5e76\u884c\uff08ILP\uff09\u4f18\u5316\u4ee3\u7801\u7684\u7279\u5b9a\u90e8\u5206\uff0c\u4ee5\u5141\u8bb8CPU\u5c3d\u53ef\u80fd\u6267\u884c\u66f4\u591a\u53ef\u4ee5\u5e76\u884c\u6267\u884c\u7684\u6307\u4ee4\u3002\u8bc6\u522b\u6307\u4ee4\u7684\u6570\u636e\u4f9d\u8d56\u95ee\u9898\uff08data hazards\uff09\u662f\u4e3b\u8981\u6b65\u9aa4\u4e4b\u4e00\u3002
"},{"location":"zh/#94","title":"\u4e0d\u4e86\u89e3\u6570\u636e\u5bf9\u9f50 (#94)","text":"\u8bb0\u4f4fGo\u4e2d\u57fa\u672c\u7c7b\u578b\u4e0e\u5176\u81ea\u8eab\u5927\u5c0f\u5bf9\u9f50\uff0c\u4f8b\u5982\uff0c\u6309\u964d\u5e8f\u4ece\u5927\u5230\u5c0f\u91cd\u65b0\u7ec4\u7ec7\u7ed3\u6784\u4f53\u7684\u5b57\u6bb5\u53ef\u4ee5\u5f62\u6210\u66f4\u7d27\u51d1\u7684\u7ed3\u6784\u4f53\uff08\u51cf\u5c11\u5185\u5b58\u5206\u914d\uff0c\u66f4\u597d\u7684\u7a7a\u95f4\u5c40\u90e8\u6027\uff09\uff0c\u8fd9\u6709\u52a9\u4e8e\u907f\u514d\u4e00\u4e9b\u5e38\u89c1\u7684\u9519\u8bef\u3002
"},{"location":"zh/#stack-vs-heap-95","title":"\u4e0d\u4e86\u89e3 stack vs. heap (#95)","text":"\u4e86\u89e3\u5806\u548c\u6808\u4e4b\u95f4\u7684\u533a\u522b\u662f\u5f00\u53d1\u4eba\u5458\u7684\u6838\u5fc3\u77e5\u8bc6\u70b9\uff0c\u7279\u522b\u662f\u8981\u53bb\u4f18\u5316\u4e00\u4e2aGo\u7a0b\u5e8f\u65f6\u3002\u6808\u5206\u914d\u7684\u5f00\u9500\u51e0\u4e4e\u4e3a\u96f6\uff0c\u800c\u5806\u5206\u914d\u5219\u8f83\u6162\uff0c\u5e76\u4e14\u4f9d\u8d56GC\u6765\u6e05\u7406\u5185\u5b58\u3002
"},{"location":"zh/#api-compiler-optimizations-and-syncpool-96","title":"\u4e0d\u77e5\u9053\u5982\u4f55\u51cf\u5c11\u5185\u5b58\u5206\u914d\u6b21\u6570 (API\u8c03\u6574, compiler optimizations, andsync.Pool
) (#96)","text":"\u51cf\u5c11\u5185\u5b58\u5206\u914d\u6b21\u6570\u4e5f\u662f\u4f18\u5316Go\u5e94\u7528\u7684\u4e00\u4e2a\u91cd\u8981\u65b9\u9762\u3002\u8fd9\u53ef\u4ee5\u901a\u8fc7\u4e0d\u540c\u7684\u65b9\u5f0f\u6765\u5b9e\u73b0,\u6bd4\u5982\u4ed4\u7ec6\u8bbe\u8ba1API\u6765\u907f\u514d\u4e0d\u5fc5\u8981\u7684\u62f7\u8d1d\uff0c\u4ee5\u53ca\u4f7f\u7528 sync.Pool
\u6765\u5bf9\u5f85\u5206\u914d\u5bf9\u8c61\u8fdb\u884c\u6c60\u5316\u3002
\u4f7f\u7528\u5feb\u901f\u8def\u5f84\u7684\u5185\u8054\u6280\u672f\u6765\u66f4\u52a0\u6709\u6548\u5730\u51cf\u5c11\u8c03\u7528\u51fd\u6570\u7684\u644a\u9500\u65f6\u95f4\u3002
"},{"location":"zh/#go-98","title":"\u4e0d\u4f7f\u7528Go\u95ee\u9898\u8bca\u65ad\u5de5\u5177 (#98)","text":"\u4e86\u89e3Go profilng\u5de5\u5177\u3001\u6267\u884c\u65f6tracer\u6765\u8f85\u52a9\u5224\u65ad\u4e00\u4e2a\u5e94\u7528\u7a0b\u5e8f\u662f\u5426\u6b63\u5e38\uff0c\u4ee5\u53ca\u5217\u51fa\u9700\u8981\u4f18\u5316\u7684\u90e8\u5206\u3002
"},{"location":"zh/#gc-99","title":"\u4e0d\u7406\u89e3GC\u662f\u5982\u4f55\u5de5\u4f5c\u7684 (#99)","text":"\u7406\u89e3\u5982\u4f55\u8c03\u4f18GC\u80fd\u591f\u5e26\u6765\u5f88\u591a\u6536\u76ca\uff0c\u4f8b\u5982\u6709\u52a9\u4e8e\u66f4\u9ad8\u6548\u5730\u5904\u7406\u7a81\u589e\u7684\u8d1f\u8f7d\u3002
"},{"location":"zh/#dockerk8sgo-100","title":"\u4e0d\u4e86\u89e3Docker\u6216\u8005K8S\u5bf9\u8fd0\u884c\u7684Go\u5e94\u7528\u7684\u6027\u80fd\u5f71\u54cd (#100)","text":"\u4e3a\u4e86\u907f\u514dCPU throttling\uff08CPU\u9650\u9891\uff09\u95ee\u9898\uff0c\u5f53\u6211\u4eec\u5728Docker\u548cKubernetes\u90e8\u7f72\u5e94\u7528\u65f6\uff0c\u8981\u77e5\u9053Go\u8bed\u8a00\u5bf9CFS(\u5b8c\u5168\u516c\u5e73\u8c03\u5ea6\u5668)\u65e0\u611f\u77e5\u3002
"}]} \ No newline at end of file diff --git a/site/sitemap.xml b/site/sitemap.xml index e4c9ef33..e9a4e675 100644 --- a/site/sitemap.xml +++ b/site/sitemap.xml @@ -2,72 +2,72 @@