.\main.go:4:1: syntax error: unexpected semicolon or newline before {
package main
import “fmt”
func main()
{
fmt.Println(“Hello world!”)
}
Correct writing style:
package main
import “fmt”
func main(){
fmt.Println(“Hello world!”)
}
error: RPC failed; curl 56 OpenSSL SSL_read: SSL_ERROR_SYSCALL, errfno 10054
fatal: The remote end hung up unexpectedly
fatal: early EOF
fatal: unpack-objects failed
Execute the pull command again after the following Settings
git config http.postBuffer 524288000
This command sets the size of the communication cache. The previous error was caused by too much synchronized data.
The config parameters here can be seen in the config file in the file directory
[core]
repositoryformatversion = 0
filemode = false
bare = false
logallrefupdates = true
symlinks = false
ignorecase = true
[remote "origin"]
url =
https://github.com/…….
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
[gui]
wmstate = normal
geometry = 841x483+111+65 321 218
[http]
postBuffer = 524288000
Map is not concurrency safe, when there are multiple concurrent growths reading and writing the same map
A panic error occurs
concurrent map writes
For example, this error occurs in the following code:
var mMap map[int]int
func TestMyMap(t *testing.T) {
mMap = make(map[int]int)
for i := 0; i < 5000; i++ {
go func() {
mMap[i] = i
}()
go readMap(i)
}
}
func readMap(i int) int {
return mMap[i]
}
There are many ways to solve this problem. Now we use read-write lock,
Concurrent access to map is not safe, and undefined behavior will appear, leading to program exit. Therefore, if you want to access the map concurrently in multiple coroutines, you must provide some synchronization mechanism. Generally, you can control the concurrent access to the map by reading and writing the lock sync.rwmutex. Encapsulating the map and sync.rwmutex can realize the secure concurrent access to the map
Code after transformation
type SMap struct {
sync.RWMutex
Map map[int]int
}
func (l *SMap) readMap(key int) (int, bool) {
l.RLock()
value, ok := l.Map[key]
l.RUnlock()
return value, ok
}
func (l *SMap) writeMap(key int, value int) {
l.Lock()
l.Map[key] = value
l.Unlock()
}
var mMap *SMap
func TestMyMap(t *testing.T) {
mMap = &SMap{
Map: make(map[int]int),
}
for i := 0; i < 5000; i++ {
go func() {
mMap.writeMap(i, i)
}()
go readMap(i)
}
}
func readMap(i int) (int, bool) {
return mMap.readMap(i)
}
There are three ways:
1. Use channel
2. Use sync. Map
3. Use map but lock it
background
Today, I set up a redis environment to test whether it is normal with simple code,
@RunWith(SpringRunner.class)
@SpringBootTest
public class SpringbootRedisApplicationTests {
@Autowired
StringRedisTemplate stringRedisTemplate;
@Test
public void saveString() {
stringRedisTemplate.opsForValue().set("accountId","123456");
Assert.assertEquals("123456",stringRedisTemplate.opsForValue().get("accountId"));
}
}
The results are as follows
org.springframework.data.redis.RedisSystemException: Redis exception; nested exception is io.lettuce.core.RedisException: io.lettuce.core.RedisConnectionException: DENIED Redis is running in protected mode because protected mode is enabled, no bind address was specified, no authentication password is requested to clients. In this mode connections are only accepted from the loopback interface. If you want to connect from external computers to Redis you may adopt one of the following solutions: 1) Just disable protected mode sending the command 'CONFIG SET protected-mode no' from the loopback interface by connecting to Redis from the same host the server is running, however MAKE SURE Redis is not publicly accessible from internet if you do so. Use CONFIG REWRITE to make this change permanent. 2) Alternatively you can just disable the protected mode by editing the Redis configuration file, and setting the protected mode option to 'no', and then restarting the server. 3) If you started the server manually just for testing, restart it with the '--protected-mode no' option. 4) Setup a bind address or an authentication password. NOTE: You only need to do one of the above things in order for the server to start accepting connections from the outside.
at org.springframework.data.redis.connection.lettuce.LettuceExceptionConverter.convert(LettuceExceptionConverter.java:74)
at org.springframework.data.redis.connection.lettuce.LettuceExceptionConverter.convert(LettuceExceptionConverter.java:41)
at org.springframework.data.redis.PassThroughExceptionTranslationStrategy.translate(PassThroughExceptionTranslationStrategy.java:44)
at org.springframework.data.redis.FallbackExceptionTranslationStrategy.translate(FallbackExceptionTranslationStrategy.java:42)
at org.springframework.data.redis.connection.lettuce.LettuceConnection.convertLettuceAccessException(LettuceConnection.java:257)
at org.springframework.data.redis.connection.lettuce.LettuceStringCommands.convertLettuceAccessException(LettuceStringCommands.java:718)
at org.springframework.data.redis.connection.lettuce.LettuceStringCommands.set(LettuceStringCommands.java:143)
at org.springframework.data.redis.connection.DefaultedRedisConnection.set(DefaultedRedisConnection.java:231)
at org.springframework.data.redis.connection.DefaultStringRedisConnection.set(DefaultStringRedisConnection.java:917)
at org.springframework.data.redis.core.DefaultValueOperations$3.inRedis(DefaultValueOperations.java:202)
at org.springframework.data.redis.core.AbstractOperations$ValueDeserializingRedisCallback.doInRedis(AbstractOperations.java:59)
at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:224)
at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:184)
at org.springframework.data.redis.core.AbstractOperations.execute(AbstractOperations.java:95)
at org.springframework.data.redis.core.DefaultValueOperations.set(DefaultValueOperations.java:198)
at com.eshare.SpringbootRedisApplicationTests.saveString(SpringbootRedisApplicationTests.java:21)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.springframework.test.context.junit4.statements.RunBeforeTestExecutionCallbacks.evaluate(RunBeforeTestExecutionCallbacks.java:73)
at org.springframework.test.context.junit4.statements.RunAfterTestExecutionCallbacks.evaluate(RunAfterTestExecutionCallbacks.java:83)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:251)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: io.lettuce.core.RedisException: io.lettuce.core.RedisConnectionException: DENIED Redis is running in protected mode because protected mode is enabled, no bind address was specified, no authentication password is requested to clients. In this mode connections are only accepted from the loopback interface. If you want to connect from external computers to Redis you may adopt one of the following solutions: 1) Just disable protected mode sending the command 'CONFIG SET protected-mode no' from the loopback interface by connecting to Redis from the same host the server is running, however MAKE SURE Redis is not publicly accessible from internet if you do so. Use CONFIG REWRITE to make this change permanent. 2) Alternatively you can just disable the protected mode by editing the Redis configuration file, and setting the protected mode option to 'no', and then restarting the server. 3) If you started the server manually just for testing, restart it with the '--protected-mode no' option. 4) Setup a bind address or an authentication password. NOTE: You only need to do one of the above things in order for the server to start accepting connections from the outside.
at io.lettuce.core.LettuceFutures.awaitOrCancel(LettuceFutures.java:125)
at io.lettuce.core.FutureSyncInvocationHandler.handleInvocation(FutureSyncInvocationHandler.java:62)
at io.lettuce.core.internal.AbstractInvocationHandler.invoke(AbstractInvocationHandler.java:80)
at com.sun.proxy.$Proxy75.set(Unknown Source)
at org.springframework.data.redis.connection.lettuce.LettuceStringCommands.set(LettuceStringCommands.java:141)
... 39 more
Caused by: io.lettuce.core.RedisConnectionException: DENIED Redis is running in protected mode because protected mode is enabled, no bind address was specified, no authentication password is requested to clients. In this mode connections are only accepted from the loopback interface. If you want to connect from external computers to Redis you may adopt one of the following solutions: 1) Just disable protected mode sending the command 'CONFIG SET protected-mode no' from the loopback interface by connecting to Redis from the same host the server is running, however MAKE SURE Redis is not publicly accessible from internet if you do so. Use CONFIG REWRITE to make this change permanent. 2) Alternatively you can just disable the protected mode by editing the Redis configuration file, and setting the protected mode option to 'no', and then restarting the server. 3) If you started the server manually just for testing, restart it with the '--protected-mode no' option. 4) Setup a bind address or an authentication password. NOTE: You only need to do one of the above things in order for the server to start accepting connections from the outside.
at io.lettuce.core.protocol.CommandHandler.onProtectedMode(CommandHandler.java:703)
at io.lettuce.core.protocol.CommandHandler.consumeResponse(CommandHandler.java:689)
at io.lettuce.core.protocol.CommandHandler.decode(CommandHandler.java:522)
at io.lettuce.core.protocol.CommandHandler.channelRead(CommandHandler.java:508)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)
at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)
at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)
at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1434)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:965)
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:163)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:646)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:581)
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:498)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:460)
at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:884)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.lang.Thread.run(Thread.java:748)
Solution
After investigation, it was not enabled when it was started redis.conf Due to configuration, the original startup command is:
./redis-server
Later, start the command and add redis.conf
configuration can connect normally
./redis-server ../redis.conf
background
Today, I created a go project and wrote a few lines of code
package chapter1
import "fmt"
func main() {
fmt.Println("hello world")
}
After running, the following exception is thrown:
runnerw.exe: CreateProcess failed with error 216:
Process finished with exit code 216
Solution
After troubleshooting, it turns out that if idea creates a go file in module package Chapter 1
, the default package name is module name package Chapter 1
, which leads to inconsistency with the name of main function. In go, package main
represents a program that can be executed independently, and each go function has its own name All applications contain a package named main
. The main function here must correspond to the imported package name package main
Just change the package name to main
to solve the problem
package main
import "fmt"
func main() {
fmt.Println("hello world")
}
Today, in Git push origin master, the error “unable to read ask pass response from ‘/ usr / libexec / openssh / Gnome SSH ask pass
appears
Search out the following paragraph. Let SSH_ Askpass can be turned off.
However, for some wierd reason, upon trying to pull/push commits from/to the Git repository, the bash shell tries to open the gnome-ssh-askpass dialogue and it fails. I wanted to prevent the bash shell from attempting to launch the dialogue box. To do this, all I had to do is run the following command in the terminal:
$ unset SSH_ ASKPASS
To prevent it in future, you can add the above line in your .bashrc or .bash_ profile.
Wish you trouble-free working!
There are several solutions:
1. If the original git used in sorcetree is embedded git, you can try to switch git to git of the system (if Git is installed in the system, you can install it yourself if not)
2. Currently, sourcetree uses git of the system, and upgrades git of the system to the latest version
I’m the second case
The GIT of the current sourcetree can be viewed in the following ways, and the grayed one is the current one
Method 1
Command: git add – U
come from
https://www.cnblogs.com/changyiqiang/p/12867839.html
(sorry for the trouble)
$git pull
$ git pull
warning: no common commits
remote: Counting objects: 5, done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 5 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (5/5), done.
From github.com:nonfuxinyang/android-study
* [new branch] master -> origin/master
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.
git pull <remote> <branch>
If you wish to set tracking information for this branch you can do so with:
git branch --set-upstream-to=origin/<branch> master
Seeing the second tip, we now know a solution. That is to specify the link relationship between the current working directory, working branch, and remote warehouse and branch. ≪ BR & gt;
for example, we set the master branch corresponding to the remote warehouse
git branch — set upstream master origin / Master
so every time we want to push or pull, we just need to enter Git push or git pull.
Before that, we have to specify the remote branch that we want to push or pull.
git push origin master
git pull origin master.
I was born in Java. Recently I became interested in go language, so I will learn it with go in the future.
After the go environment is installed and configured, the vscode development tool is installed, and the first go program is written. It’s very simple, just a simple output statement, but it does
Go run: cannot run non main package. The code is as follows:
package test
import "fmt"
func main() {
fmt.Println("cainiaobulan testing go")
}
The error message of go is very straightforward. The main method can only be placed in package main. Go run is to execute the command and a main must be used to call it. Install can be directly compiled into a package file or an EXE (if there is a main function)
Change the code and run OK
package main
import "fmt"
func main() {
fmt.Println("cainiaobulan testing go")
}
Just take this mistake as the first step for me to learn go. In the future, I can cross the pit step by step. I hope that children’s shoes with the same interest can learn together and carry forward go. At the same time, I also want to seek guidance from the boss. I am ready to develop in the direction of go web.
HEAD
Git reported the above error, which literally means “wrong default version of head”. Let’s figure out what head
is. The GIT manual says:
The head file is a symbolic reference to the branch you’re currently on. By symbolic reference, we mean that unlike a normal reference, it doesn’t generally contain a SHA-1 value but rather a point to another reference.
the head file is a symbolic reference to the current branch. By symbolic reference, we mean that, unlike a normal reference, it usually does not contain a SHA-1 value, but a pointer to another reference.
In short, the head
file points to the current branch. If you do not create a custom branch, head
points to the Master
branch by default. Open the head
file, and you can see:
$ cat .git/HEAD
ref: refs/heads/master
The head
file is a link file of the file refs / heads / Master
. When we create a new user-defined branch, such as dev
, switch to the branch and submit the modification under the branch, head
points to the branch where the modification was made dev
, and open the head
file
$ cat .git/HEAD
ref: refs/heads/dev
Therefore, GIT reports an error bad default revision 'head'
, which means that the current branch of head is wrong.
terms of settlement
You can also manually edit this file, but again a safer command exists to do so:
symbolic ref
.
you can modify thehead
file manually, but there is a more secure command to do it: symbolic Ref.
for example, I changed head
from pointing to Master
to pointing to dev
:
git symbolic-ref HEAD refs/heads/dev
Switch branches and submit again
reference resources
Git: fatal: bad default revision ‘head’ git internal – git references creating and merging branches – Liao Xuefeng git tutorial
Git push to remote warehouse failed
Error prompt:
fatal: remote part of refspec is not a valid name in https://github.com/Aero-ku/
musicplayer.git